reportFinalizedResult

Class: matlab.unittest.plugins.TestRunnerPlugin
Package: matlab.unittest.plugins

Enable reporting of finalized TestResults

A plugin that overrides the reportFinalizedResult method is recommended for streaming or inline reporting of test results. If you implement this method, the test runner reports the results as soon as they are finalized. The plugin can then report test results while the test runner is still running the test suite, rather than waiting until the entire test suite is complete.

Syntax

reportFinalizedResult(plugin,pluginData)

Description

example

reportFinalizedResult(plugin,pluginData) enables the reporting of finalized TestResults. The test runner uses this method to report finalized test results to the plugin. By overriding the method in your TestRunnerPlugin class, you can report information about each test result as soon as the test runner determines the test is finalized.

The test framework evaluates this method as soon as it can guarantee that the test result is finalized for a test suite element. It can evaluate this method within the scope of the runTestSuite, runTestClass, or runTest methods of the TestRunnerPlugin.

Input Arguments

expand all

Plugin instance, specified as an instance of the matlab.unittest.plugins.TestRunnerPlugin class.

Finalized test information, specified as an instance of the matlab.unittest.plugins.plugindata.FinalizedResultPluginData class. The test framework uses this information to describe the test content to the plugin.

Examples

expand all

Use the reportFinalizedResult method to display the status of each test element.

Create the following plugin in a file,ExamplePlugin.m, in your current working folder.

classdef ExamplePlugin < matlab.unittest.plugins.TestRunnerPlugin
    methods (Access = protected)
        function reportFinalizedResult(plugin, pluginData)
            thisResult = pluginData.TestResult;
            if thisResult.Passed
                status = 'PASSED';
            elseif thisResult.Failed
                status = 'FAILED';
            elseif thisResult.Incomplete
                status = 'SKIPPED';
            end
            fprintf('%s: %s in %f seconds.\n',thisResult.Name,...
                status,thisResult.Duration)
            reportFinalizedResult@...
                matlab.unittest.plugins.TestRunnerPlugin(plugin,pluginData);
        end
    end
end

Create the following test class in a file, ExampleTest.m, in your current working folder.

classdef ExampleTest < matlab.unittest.TestCase
    methods(Test)
        function testOne(testCase)
            testCase.assertGreaterThan(5,1)
        end
        function testTwo(testCase)
            wrongAnswer = 'wrong';
            testCase.verifyEmpty(wrongAnswer,'Not Empty')
            testCase.verifyClass(wrongAnswer,'double','Not double')
        end
        function testThree(testCase)
            testCase.assumeEqual(7*2,13,'Values not equal')
        end
        function testFour(testCase)
            testCase.verifyEqual(3+2,5);
        end
    end
end

At the command prompt, create a test suite, add the plugin to the test runner, and run the tests.

import matlab.unittest.TestSuite
import matlab.unittest.TestRunner

suite = TestSuite.fromClass(?ExampleTest);
runner = TestRunner.withNoPlugins;
runner.addPlugin(ExamplePlugin)
result = runner.run(suite);
ExampleTest/testOne: PASSED in 0.002216 seconds.
ExampleTest/testTwo: FAILED in 0.006105 seconds.
ExampleTest/testThree: SKIPPED in 0.007458 seconds.
ExampleTest/testFour: PASSED in 0.004865 seconds.

More About

expand all

Introduced in R2015b

Was this topic helpful?