Main Content

sltest.testmanager.TestResultContainer Class

Namespace: sltest.testmanager

Container for MLDATX test file results from MATLAB Unit Test run or runInParallel

Since R2022b


sltest.testmanager.TestResultContainer holds an sltest.testmanager.TestCaseResult or sltest.testmanager.TestIterationResult in the Details property of a matlab.unittest.TestResult object. A TestResultContainer object is created when you run a test using the matlab.unittest.TestRunner run or runInParallel methods for test cases saved in a Simulink® Test™ MLDATX test file. An sltest.testmanager.TestResultContainer object is created only when you use the sltest.plugins.TestManagerResultsPlugin.

The sltest.testmanager.TestResultContainer class is a handle class.


Do not create an sltest.testmanager.TestResultContainer object. The TestResultContainer object is created automatically when you use the sltest.plugins.TestManagerResultsPlugin and run test cases saved in a Simulink Test MLDATX test file.


expand all

Result of using MATLAB Unit Test framework run or runInParallel on test cases in a Simulink Test MLDATX test file, returned in a TestResultContainer as a sltest.testmanager.TestCaseResult or sltest.testmanager.TestIterationResult object.




collapse all

This example shows how to include Test Manager Results in a TestResult object produced using the MATLAB Unit Test framework. The results are stored in a TestResultContainer object.

The test case creates a square wave input to a controller subsystem and sweeps through 25 iterations of parameters a and b. The test compares the alpha output to a baseline with a tolerance of 0.0046. Output that exceeds this tolerance fails the test.

1. Set the path to the test file.

testfile = 'f14ParameterSweepTest.mldatx';

2. Create the TestSuite object.

import matlab.unittest.TestSuite
suite = testsuite(testfile);

3. Create the TestRunner object.

import matlab.unittest.TestRunner
runner = TestRunner.withNoPlugins;

4. Add the TestManagerResultsPlugin to the TestRunner.

tmr = sltest.plugins.TestManagerResultsPlugin; 

5. Run the test.

results = run(runner,suite);

6. View results of 19th iteration, a test failure.

failure = results(19)
failure = 
  TestResult with properties:

          Name: 'f14ParameterSweepTest > New Test Suite 1/Iterations Parameter Sweep(ScriptedIteration=Scripted_Iteration19)'
        Passed: 0
        Failed: 1
    Incomplete: 0
      Duration: 2.1611
       Details: [1x1 struct]

   0 Passed, 1 Failed, 0 Incomplete.
   2.1611 seconds testing time.

In the Details field of the TestResult object, test Iteration results are stored in a TestResultContainer object, which you do not interact with directly. The TestResultContainer object contains the test case or test iteration object, which you can use to retrieve test result information, such as the type of test case, the cause of the failure, and the values of the parameters that led to the failure.

failresult = failure.Details.SimulinkTestManagerResults.TestResult;
ans = 
'Baseline Test'
ans = 
'Failed criteria: Baseline'
ans = struct with fields:
      parameterName: 'a'
             source: 'base workspace'
              value: 2.6000
       displayValue: '2.6'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

ans = struct with fields:
      parameterName: 'b'
             source: 'base workspace'
              value: 66
       displayValue: '66'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

Version History

Introduced in R2022b