matlab.unittest.TestRunner.withTextOutput

Class: matlab.unittest.TestRunner
Package: 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 Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside quotes. You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

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.unittest.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.unittest.Verbosity enumeration.

By default the TestRunner includes diagnostics logged at the matlab.unittest.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.unittest.Verbosity enumeration object. Integer values correspond to the members of the matlab.unittest.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.unittest.Verbosity.Detailed level (level 3) and test run progress at the matlab.unittest.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

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(?mypackage.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,matlab.unittest.Verbosity.Detailed,'Starting Test')
            log(testCase,'Testing 5==5')
            testCase.verifyEqual(5,5)
            log(testCase,matlab.unittest.Verbosity.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 (2018-04-12 12:53:47): Starting Test

[Concise] Diagnostic logged (2018-04-12 12:53:47): Testing 5==5

[Verbose] Diagnostic logged (2018-04-12 12:53:47): Test Complete
.
Done ExampleLogTest
__________