Main Content

reportFinalizedResult

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

Enable 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 TestRunner 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 TestRunner 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 of TestRunnerPlugin.

Input Arguments

expand all

Plugin object, 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 testing framework uses this information to describe the test content to the plugin.

Examples

expand all

Display the status of each Test element by using the reportFinalizedResult method.

Create the plugin file ExamplePlugin.m in your current 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 test class file 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 TestRunner, 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.
Introduced in R2015b