matlab.unittest.plugins.plugindata.ResultDetails.append - Add data to test result details - MATLAB (original) (raw)
Class: matlab.unittest.plugins.plugindata.ResultDetails
Namespace: matlab.unittest.plugins.plugindata
Add data to test result details
Syntax
Description
append([resultDetails](#mw%5Fb05208bd-9f83-42f1-ac75-2c8dc85b98c3),[field](#mw%5F1d1f247c-364c-4d1b-857b-138791f608ee),[data](#mw%5Fe14d2ce4-57f5-4541-8151-d886663039a2))
appends data
to a field
of theDetails
property of a TestResult
array. Iffield
does not exist, the method adds it to theDetails
structure and stores data
in the added field.
When you invoke append
within the scope of a plugin class method, the append operation applies to all of the TestResult
objects affected by the plugin method. For example, if you invoke append
within the scope of therunSession
method of TestRunnerPlugin
, then the same data is added to all TestResult
objects belonging to the test session.
Input Arguments
Modifier of the test result details, specified as an instance of thematlab.unittest.plugins.plugindata.ResultDetails
class.
Field name, specified as a character vector or string scalar. Valid field names begin with a letter and can contain letters, digits, and underscores. The maximum length of a field name is the value that the namelengthmax
function returns.
Data to append to the field, specified as a scalar or an array of objects. For example, you can specify data
as a numeric scalar, string array, cell array, structure, or class object.
You can call the append
method on a specific field and append data to that field as many times as you want. If you append elements of unlike classes to a field, MATLAB® converts some elements so that all elements in the field are of the same type. For more information, see Valid Combinations of Unlike Classes.
Examples
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 classExamplePlugin
, which overrides therunTestSuite
method of TestRunnerPlugin
. Add aGroup
field containing the group number to theDetails
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, addExamplePlugin
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
Extended Capabilities
Version History
Introduced in R2020a