Main Content

matlab.unittest.plugins.ToStandardOutput class

Package: matlab.unittest.plugins
Superclasses: matlab.unittest.plugins.OutputStream

Output stream to display text information to screen


The ToStandardOutput class creates an output stream to display text output to the screen. Many plugins that accept an output stream use ToStandardOutput as their default stream.


matlab.unittest.plugins.ToStandardOutput creates an OutputStream that prints text output to the screen.

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects.


collapse all

In your working folder, create the file ExampleTest.m containing the following test class.

classdef ExampleTest < matlab.unittest.TestCase
        function testOne(testCase)  % Test fails
            testCase.verifyEqual(5, 4, 'Testing 5==4')
        function testTwo(testCase)  % Test passes
            testCase.verifyEqual(5, 5, 'Testing 5==5')
        function testThree(testCase)
            % test code

The verifyEqual qualification in testOne causes a test failure. The qualifications in testOne and testTwo include an instance of a matlab.unittest.diagnostics.StringDiagnostic.

At the command prompt, create a test suite from the ExampleTest class.

import matlab.unittest.TestRunner
import matlab.unittest.TestSuite
import matlab.unittest.plugins.DiagnosticsOutputPlugin
import matlab.unittest.plugins.ToStandardOutput

suite   = TestSuite.fromClass(?ExampleTest);

Create a test runner with no plugins. This code creates a silent runner and provides you with complete control over the installed plugins.

runner = TestRunner.withNoPlugins;

Create a DiagnosticsOutputPlugin that explicitly specifies that its output should go to the screen.

plugin = DiagnosticsOutputPlugin(ToStandardOutput);

Add the plugin to the TestRunner and run the suite.

result =;
Verification failed in ExampleTest/testOne.

    Test Diagnostic:
    Testing 5==4

    Framework Diagnostic:
    verifyEqual failed.
    --> The values are not equal using "isequaln".
    --> Failure table:
            Actual    Expected    Error    RelativeError
            ______    ________    _____    _____________
              5          4          1          0.25     
    Actual Value:
    Expected Value:

    Stack Information:
    In C:\work\ExampleTest.m (ExampleTest.testOne) at 4
Failure Summary:

     Name                 Failed  Incomplete  Reason(s)
     ExampleTest/testOne    X                 Failed by verification.

Only the test failures produce output to the screen.

Introduced in R2014a