matlab.unittest.TestRunner.withTextOutput - Create test runner configured for text output - MATLAB (original) (raw)
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 aTestRunner
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](#namevaluepairarguments))
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
Specify optional pairs of arguments asName1=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 from0
through 4
, a matlab.automation.Verbosity enumeration object, or a text representation of the enumeration.
Numeric Representation | Enumeration Member Name | Verbosity Description |
---|---|---|
0 | None | No information |
1 | Terse | Minimal information |
2 | Concise | Moderate amount of information |
3 | Detailed | Some supplemental information |
4 | Verbose | Lots of supplemental information |
By default, the test runner displays failing and logged events at thematlab.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 from0
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 Representation | Enumeration Member Name | Verbosity Description |
---|---|---|
0 | None | No information |
1 | Terse | Minimal information |
2 | Concise | Moderate amount of information |
3 | Detailed | Some supplemental information |
4 | Verbose | Lots of supplemental information |
By default, the test runner includes diagnostics logged at thematlab.automation.Verbosity.Terse
level (level 1). To exclude logged diagnostics, specify LoggingLevel
asmatlab.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.
Examples
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