This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


Class: matlab.unittest.TestRunner
Package: matlab.unittest

Create TestRunner object for command window output


runner = matlab.unittest.TestRunner.withTextOutput
runner = matlab.unittest.TestRunner.withTextOutput('Verbosity',v)


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('Verbosity',v) reacts to messages logged at or below the specified verbosity level and controls the level of detail about the test run that is displayed in the Command Window.

Input Arguments

expand all

Verbosity levels supported by the test runner, specified as an integer value between 1 and 4 or a matlab.unittest.Verbosity enumeration object. The runner reacts to diagnostics that are logged at this level and lower. Integer values correspond to the members of the matlab.unittest.Verbosity enumeration.

Numeric RepresentationCorresponding Enumeration ObjectVerbosity Description

Minimal amount of information


Typical amount of information


Supplemental amount of information


Surplus of information

Output Arguments


matlab.unittest.TestRunner object.



To learn about attributes of methods, see Method Attributes in the MATLAB Object-Oriented Programming documentation.


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 produced 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
        function testOne(testCase)
            log(testCase,matlab.unittest.Verbosity.Detailed,'Starting Test')
            log(testCase,'Testing 5==5')
            log(testCase,matlab.unittest.Verbosity.Verbose,'Test Complete')

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('Verbosity',4);

results =;
 Running ExampleLogTest
  Setting up ExampleLogTest
  Done setting up ExampleLogTest in 0 seconds
   Running ExampleLogTest/testOne
    Evaluating Test: testOne
[Detailed] Diagnostic logged (2014-04-18T14:28:19): Starting Test
 [Concise] Diagnostic logged (2014-04-18T14:28:19): Testing 5==5
 [Verbose] Diagnostic logged (2014-04-18T14:28:20): Test Complete
   Done ExampleLogTest/testOne in 0.21106 seconds
  Tearing down ExampleLogTest
  Done tearing down ExampleLogTest in 0 seconds
 Done ExampleLogTest in 0.21106 seconds
Was this topic helpful?