Main Content

matlab.unittest.plugins.DiagnosticsValidationPlugin Class

Namespace: matlab.unittest.plugins
Superclasses: matlab.unittest.plugins.TestRunnerPlugin, matlab.unittest.plugins.Parallelizable

Plugin to help validate diagnostic code


The matlab.unittest.plugins.DiagnosticsValidationPlugin class provides a plugin to help validate diagnostic code. To confirm that user-supplied diagnostics execute correctly, add a DiagnosticsValidationPlugin instance to the test runner.

DiagnosticsValidationPlugin is useful because tests do not necessarily encounter failure conditions. If a programming error exists in the diagnostic code, the error might not become evident unless the test fails. The plugin unconditionally evaluates the diagnostics, regardless of whether the tests pass or fail, and helps you confirm that the diagnostic code is free of programming errors.

The matlab.unittest.plugins.DiagnosticsValidationPlugin class is a handle class.




plugin = matlab.unittest.plugins.DiagnosticsValidationPlugin creates a plugin to help validate diagnostic code. The plugin directs its text output to the screen.

plugin = matlab.unittest.plugins.DiagnosticsValidationPlugin(stream) creates a plugin that writes its data to the specified output stream.

Input Arguments

expand all

Location where the plugin directs text output, specified as a matlab.automation.streams.OutputStream object. By default, the plugin directs its output to the screen.


collapse all

Validate diagnostic code by using the DiagnosticsValidationPlugin class.

In a file named ExampleTest.m in your current folder, create the ExampleTest class. Even though all the tests in the test class pass, the testThree method includes an intentional error in the supplied diagnostic.

classdef ExampleTest < matlab.unittest.TestCase
    methods (Test)
        function testOne(~)
            % Test code

        function testTwo(~)
            % Test code
        function testThree(testCase)
            % This test should use @dir as a function handle,
            % but there is a typo

Import the DiagnosticsValidationPlugin class.

import matlab.unittest.plugins.DiagnosticsValidationPlugin

Create a test suite from the ExampleTest class.

suite = testsuite("ExampleTest");

Create a default test runner and use it to run the tests. The testing framework does not encounter the bug in the diagnostic code of testThree because the test passes.

runner = testrunner;
results1 =;
Running ExampleTest
Done ExampleTest

Now, add a DiagnosticsValidationPlugin instance to the test runner and run the tests. The framework executes the diagnostic code specified by the function handle, even though testThree passes, and encounters the bug.

results2 =;
Running ExampleTest
Validation of Test Diagnostic:
Error occurred while capturing diagnostics:
    Error using evalc
    Unrecognized function or variable 'dri'.
    Error in ExampleTest/testThree (line 14)
Done ExampleTest


  • The diagnostic analysis can reduce the testing performance and result in verbose text output. Consider these factors before using the plugin when running your tests.

Version History

Introduced in R2013a