Main Content

matlab.unittest.TestRunner.withTextOutput

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

Create test runner configured for text 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. The output produced includes test progress as well as diagnostics in the event of test failures.

runner = matlab.unittest.TestRunner.withTextOutput(Name=Value) specifies options using one or more name-value arguments. For example, runner = matlab.unittest.TestRunner.withTextOutput(LoggingLevel="None") creates a test runner that excludes logged diagnostics.

Name-Value Arguments

expand all

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.

Example: runner = matlab.unittest.TestRunner.withTextOutput(OutputDetail=4)

Display level of test output, specified as an integer scalar from 0 through 4, a matlab.automation.Verbosity enumeration object, or a text representation of the enumeration.

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

By default, the test runner 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).

Verbosity level of logged diagnostics, specified as an integer scalar from 0 through 4, a matlab.automation.Verbosity enumeration object, or a text representation of the enumeration. The test runner includes diagnostics logged at the specified level and below.

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

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

Logged diagnostics are diagnostics that you supply to the unit testing framework with the log (TestCase) and log (Fixture) methods.

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