Main Content

matlab.unittest.TestRunner.withTextOutput

Class: matlab.unittest.TestRunner
Namespace: matlab.unittest

Create TestRunner object for command window output

Syntax

runner = matlab.unittest.TestRunner.withTextOutput
runner = matlab.unittest.TestRunner.withTextOutput(Name,Value)

Description

runner = matlab.unittest.TestRunner.withTextOutput creates a TestRunner object that is configured for running tests from the MATLAB® Command Window and returns it in runner. The output produced includes test progress as well as diagnostics in the event of test failures.

runner = matlab.unittest.TestRunner.withTextOutput(Name,Value) creates a TestRunner with additional options specified by one or more Name,Value pair arguments. For example, to create a TestRunner that excludes logged diagnostics, specify matlab.unittest.TestRunner.withTextOutput('LoggingLevel',0).

Input Arguments

expand all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: matlab.unittest.TestRunner.withTextOutput('OutputDetail',4) displays event detail at them most verbose level.

Maximum verbosity level for logged diagnostics included by the TestRunner instance, specified as an integer value from 0 through 4, a matlab.automation.Verbosity enumeration object, or a string scalar or character vector corresponding to one of the predefined enumeration member names. The TestRunner includes diagnostics that are logged at this level and below. Integer values correspond to the members of the matlab.automation.Verbosity enumeration.

By default the TestRunner includes diagnostics logged at the matlab.automation.Verbosity.Terse level (level 1). To exclude logged diagnostics, specify LoggingLevel as Verbosity.None (level 0).

Logged diagnostics are diagnostics that you supply to the testing framework with a call to the log (TestCase) or log (Fixture) method.

Numeric RepresentationEnumeration Member NameVerbosity Description
0None

No information

1Terse

Minimal information

2Concise

Moderate amount of information

3Detailed

Some supplemental information

4Verbose

Lots of supplemental information

Display level for event details, specified as an integer value from 0 through 4, or as a matlab.automation.Verbosity enumeration object. Integer values correspond to the members of the matlab.automation.Verbosity enumeration, or a string scalar or character vector corresponding to one of the predefined enumeration member names.

The TestRunner displays failing and logged events with the amount of detail specified by OutputDetail. By default, the TestRunner displays failing and logged events at the matlab.automation.Verbosity.Detailed level (level 3) and test run progress at the matlab.automation.Verbosity.Concise level (level 2).

Numeric RepresentationEnumeration Member NameVerbosity Description
0None

No information

1Terse

Minimal information

2Concise

Moderate amount of information

3Detailed

Some supplemental information

4Verbose

Lots of supplemental information

Attributes

Statictrue

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Add matlab.unittest classes to the current import list.

import matlab.unittest.TestRunner
import matlab.unittest.TestSuite

Create a TestSuite array.

suite = TestSuite.fromClass(?myNamespace.MyTestClass);

Create a TestRunner object that produces output to the Command Window.

runner = TestRunner.withTextOutput;

% Run the suite
result = run(runner,suite)

Create the follow class In a file in your current working folder, ExampleLogTest.m.

classdef ExampleLogTest < matlab.unittest.TestCase
    methods(Test)
        function testOne(testCase)
            log(testCase,'Detailed','Starting Test')
            log(testCase,'Testing 5==5')
            testCase.verifyEqual(5,5)
            log(testCase,'Verbose','Test Complete')
        end
    end
end

At the command prompt, run the test.

result = run(ExampleLogTest);
Running ExampleLogTest
.
Done ExampleLogTest
__________

Create a test runner to display logged messages at verbosity level 4 and lower, and then run the test.

import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
suite = TestSuite.fromClass(?ExampleLogTest);
runner = TestRunner.withTextOutput('LoggingLevel',4);

results = runner.run(suite);
Running ExampleLogTest

[Detailed] Diagnostic logged (2022-10-15 18:39:59): Starting Test

[Concise] Diagnostic logged (2022-10-15 18:39:59): Testing 5==5

[Verbose] Diagnostic logged (2022-10-15 18:39:59): Test Complete
.
Done ExampleLogTest
__________

Version History

Introduced in R2013a