matlab.unittest.plugins.DiagnosticsValidationPlugin - Plugin to help validate diagnostic code - MATLAB (original) (raw)

Main Content

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

Plugin to help validate diagnostic code

Description

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.

Creation

Description

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

example

plugin = matlab.unittest.plugins.DiagnosticsValidationPlugin([stream](#mw%5F514571a7-1887-4070-8619-00359d563ee8)) creates a plugin that writes its data to the specified output stream.

Input Arguments

Examples

collapse all

Validate diagnostic code by using theDiagnosticsValidationPlugin class.

In a file named ExampleTest.m in your current folder, create theExampleTest 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 end

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

end

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 = runner.run(suite);

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.

runner.addPlugin(DiagnosticsValidationPlugin) results2 = runner.run(suite);

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)
            testCase.verifyEqual("myFile","myFile",@dri)

. Done ExampleTest


Tips

Version History

Introduced in R2013a