Main Content

sltest.plugins.TestManagerResultsPlugin class

Package: 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 Details field of each TestResult object.

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-separate 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.

Example: 'ExportToFile','myfile'

Example: 'ExportToFile','myfile.mldatx'

Examples

collapse all

This example shows how to include Test Manager Results in a TestResult object produced through the MATLAB Unit Test framework.

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

Totals:
   0 Passed, 1 Failed, 0 Incomplete.
   0.69645 seconds testing time.

In the Details field of the TestResult object, test Iteration results appear as a SimulinkTestManagerResults object. The SimulinkTestManagerResults object contains information such as the type of test case, the cause of the failure, and the values of the parameters that led to the failure.

failure.Details.SimulinkTestManagerResults.TestCaseType
ans = 
'Baseline Test'
failure.Details.SimulinkTestManagerResults.CauseOfFailure
ans = 
'Failed criteria: Baseline'
failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(1)
ans = struct with fields:
      parameterName: 'a'
             source: 'base workspace'
              value: 2.6000
       displayValue: '2.6'
    simulationIndex: 1

failure.Details.SimulinkTestManagerResults.IterationSettings.variableParameters(2)
ans = struct with fields:
      parameterName: 'b'
             source: 'base workspace'
              value: 66
       displayValue: '66'
    simulationIndex: 1

Version History

Introduced in R2018b