Main Content

matlab.unittest.plugins.plugindata.ResultDetails class

Package: matlab.unittest.plugins.plugindata

Class for modifying test result details

Description

The ResultDetails class enables a TestRunnerPlugin instance to modify the Details property of a TestResult array. To modify the Details structure, invoke a method of ResultDetails within the scope of a plugin class method. The TestRunner instantiates this class, so you are not required to create an object of the class directly.

Note

Finalized test results cannot be modified by ResultDetails. A test result is finalized when it is no longer possible for any qualifications to modify it.

Methods

expand all

Examples

collapse all

The testing framework can divide the test suite into separate groups and run each group on the current parallel pool (requires Parallel Computing Toolbox™). Create a plugin that adds the group number to TestResult objects.

In a file in your current folder, create the parallelizable plugin class ExamplePlugin, which overrides the runTestSuite method of TestRunnerPlugin. Add a Group field containing the group number to the Details property of the TestResult objects corresponding to the group.

classdef ExamplePlugin < ...
        matlab.unittest.plugins.TestRunnerPlugin & ...
        matlab.unittest.plugins.Parallelizable
    
    methods (Access = protected)
        function runTestSuite(plugin,pluginData)
            
            % Inspect pluginData to get the TestSuite group number
            groupNumber = pluginData.Group;
            
            % Add the group number to TestResult objects
            resultDetails = pluginData.ResultDetails;
            resultDetails.append('Group',groupNumber)
            
            % Invoke the superclass method
            runTestSuite@matlab.unittest.plugins.TestRunnerPlugin(plugin,pluginData);
        end    
    end
end

In your current folder, create a file named ExampleTest.m containing this parameterized test class. This class results in 300 tests for comparing pseudorandom integers between 1 and 10.

classdef ExampleTest < matlab.unittest.TestCase
    properties (TestParameter)
        num1 = num2cell(randi(10,1,10));
        num2 = num2cell(randi(10,1,10));
    end
    
    methods(Test)
        function testAssert(testCase,num1,num2)
            testCase.assertNotEqual(num1,num2)
        end
        function testVerify(testCase,num1,num2)
            testCase.verifyNotEqual(num1,num2)
        end
        function testAssume(testCase,num1,num2)
            testCase.assumeNotEqual(num1,num2)
        end
    end
end

At the command prompt, create a test suite from the ExampleTest class.

suite = testsuite('ExampleTest');

Create a TestRunner instance with no plugins, add ExamplePlugin to the runner, and then run the tests in parallel.

import matlab.unittest.TestRunner
runner = TestRunner.withNoPlugins;
runner.addPlugin(ExamplePlugin)
result = runner.runInParallel(suite);
Split tests into 18 groups and running them on 6 workers.
----------------
Finished Group 1
----------------

----------------
Finished Group 2
----------------

----------------
Finished Group 3
----------------

----------------
Finished Group 4
----------------

----------------
Finished Group 5
----------------

----------------
Finished Group 6
----------------

----------------
Finished Group 7
----------------

----------------
Finished Group 8
----------------

----------------
Finished Group 9
----------------

-----------------
Finished Group 10
-----------------

-----------------
Finished Group 11
-----------------

-----------------
Finished Group 12
-----------------

-----------------
Finished Group 13
-----------------

-----------------
Finished Group 14
-----------------

-----------------
Finished Group 15
-----------------

-----------------
Finished Group 16
-----------------

-----------------
Finished Group 17
-----------------

-----------------
Finished Group 18
-----------------

Retrieve the group number for the first and last Test elements.

groupOfFirst = result(1).Details.Group
groupOfLast = result(end).Details.Group
groupOfFirst =

     1


groupOfLast =

    18
Introduced in R2020a