Main Content

sltest.plugins.TestManagerResultsPlugin Class

Namespace: sltest.plugins

Generate enhanced test results with the MATLAB Unit Test framework

Description

Use the sltest.plugins.TestManagerResultsPlugin class to include Test Manager results when using the MATLAB® Unit Test framework to run Simulink® Test™ files. Test Case and Test Iteration results appear in the TestResultContainer class.

To publish Test Manager results, configure your test file for reporting and add the TestReportPlugin and TestManagerResultsPlugin classes to the TestRunner object. Test Case and Test Iteration results appear in the Details section of the MATLAB Test Report. For more information, see Test a Model for Continuous Integration Systems.

Creation

tmr = sltest.plugins.TestManagerResultsPlugin creates an sltest.plugins.TestManagerResultsPlugin plugin object tmr. You use the plugin object only to direct the TestRunner to produce an enhanced test result.

You can also import the plugin, and then use the class name to create the object:

import sltest.plugins.TestManagerResultsPlugin
tmr = TestManagerResultsPlugin

Input Arguments

expand all

Name-Value Arguments

Specify optional pairs of arguments as Name1=Value1,...,NameN=ValueN, where Name is the argument name and Value is the corresponding value. Name-value arguments must appear after other arguments, but the order of the pairs does not matter.

Before R2021a, use commas to separate each name and value, and enclose Name in quotes.

Example: 'ExportToFile','myfile'

Optional file to save results in Simulink Test MLDATX format, specified as the comma-separated pair consisting of 'ExportToFile' and the file name.

You can open the MLDATX results file in the Test Manager by clicking the Import button on the toolbar.

Note

Make sure that the sltest.plugins.TestManagerResultsPlugin is added only once to the TestRunner object. Adding the plugin more than once might cause issues with exporting the test results file.

Example: 'ExportToFile','myfile'

Example: 'ExportToFile','myfile.mldatx'

Examples

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; 
addPlugin(runner,tmr)

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: 0.7124
       Details: [1x1 struct]

Totals:
   0 Passed, 1 Failed, 0 Incomplete.
   0.71235 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;
failresult.TestCaseType
ans = 
'Baseline Test'
failresult.CauseOfFailure
ans = 
'Failed criteria: Baseline'
failresult.IterationSettings.variableParameters(1)
ans = struct with fields:
      parameterName: 'a'
             source: 'base workspace'
              value: 2.6000
       displayValue: '2.6'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

failresult.IterationSettings.variableParameters(2)
ans = struct with fields:
      parameterName: 'b'
             source: 'base workspace'
              value: 66
       displayValue: '66'
    simulationIndex: 1
     rrPropertyType: ''
     rrPropertyName: ''

Version History

Introduced in R2018b