Main Content

reportFinalizedResult

Class: matlab.unittest.plugins.TestRunnerPlugin
Namespace: matlab.unittest.plugins

Extend reporting of finalized test results

Description

example

reportFinalizedResult(plugin,pluginData) enables the reporting of finalized test results. A test result is finalized when it is no longer possible for any qualifications to modify it. The test runner might modify previously run test results when it executes code inside TestClassTeardown methods or tears down shared test fixtures, for example.

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 suite is still running, rather than waiting until the entire suite is complete. The testing framework can evaluate reportFinalizedResult within the scope of the runTestSuite, runTestClass, or runTest methods.

Input Arguments

expand all

Plugin, specified as a matlab.unittest.plugins.TestRunnerPlugin object.

Finalized test information, specified as a matlab.unittest.plugins.plugindata.FinalizedResultPluginData object. The testing framework uses this information to describe the test content to the plugin.

Attributes

Accessprotected

To learn about attributes of methods, see Method Attributes.

Examples

expand all

Create a plugin in a file named ExamplePlugin.m in your current folder. Override the reportFinalizedResult method to display the status of each Test element.

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 this test class in a file named ExampleTest.m in your current 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.

Version History

Introduced in R2015b