matlab.unittest.plugins.FailureDiagnosticsPlugin class

Package: matlab.unittest.plugins

Plugin to show diagnostics on failure


The FailureDiagnosticsPlugin creates a plugin to show diagnostics upon encountering a test failure. Add it to the TestRunner to output test failure diagnostics to the Command Window. This plugin is used by default when you construct a test runner using TestRunner.withTextOutput.


matlab.unittest.plugins.FailureDiagnosticsPlugin creates a plugin to show diagnostics upon encountering a test failure.

matlab.unittest.plugins.DFailureDiagnosticsPlugin(stream) redirects all the text output to the output stream, stream. If you do not specify the output stream, the plugin uses the ToStandardOutput stream.

Input Arguments


Location where the plugin directs text output, specified as an OutputStream.

Default: ToStandardOutput

Copy Semantics

Handle. To learn how handle classes affect copy operations, see Copying Objects in the MATLAB® documentation.


expand all

Add Plugin to TestRunner

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

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

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.FailureDiagnosticsPlugin

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;

Run the tests.

result1 =;

No output is displayed, but result1 contains information about the failed test.

Add FailureDiagnosticsPlugin to the runner and run the tests.

result2 =;
Verification failed in ExampleTest/testOne.

    Test Diagnostic:
    Testing 5==4

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

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

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

The framework displays the DiagnosticResult of the StringDiagnostic for failed tests only. It also displays additional framework diagnostics. The TestResult object, result2, is the same as result1.

Was this topic helpful?