Main Content

sltest.plugins.coverage.ModelCoverageReport Class

Namespace: sltest.plugins.coverage
Superclasses: matlab.mixin.Heterogeneous

Specify model coverage report details for tests run with MATLAB Unit Test


Use the sltest.plugins.coverage.ModelCoverageReport class to specify the coverage report details and the file name and location for tests run with the MATLAB® Unit Test framework. If you have a license for Parallel Computing Toolbox™, you can use the ModelCoverageReport with parallel test execution.

The sltest.plugins.coverage.ModelCoverageReport class is a handle class.

Class Attributes


For information on class attributes, see Class Attributes.


mcr = sltest.plugins.coverage.ModelCoverageReport creates a model coverage report after the test runs. The report uses a default name and is saved in the current working folder.

mcr = sltest.plugins.coverage.ModelCoverageReport(path) uses a default name and saves the report in the folder specified by the path.

mcr = sltest.plugins.coverage.ModelCoverageReport('ReportName',name) uses the specified report name with the model name appended to it, and saves the report in the current working folder. For example, for an HTML report, if you specify the report name as MyReport and the model being tested is myModel, the report name is MyReport_mymodel.html.

mcr = sltest.plugins.coverage.ModelCoverageReport(path,'ReportName',name) uses the specified report name and saves the report in the folder specified by the path.

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

import sltest.plugins.coverage.ModelCoverageReport
mcr = ModelCoverageReport(path)

Use ModelCoveragePlugin to specify report properties before you run the test:

  1. Create a ModelCoverageReport.

  2. Create a ModelCoveragePlugin, and specify the ModelCoverageReport by using the Producing property.

  3. Add the ModelCoveragePlugin to the TestRunner.

  4. Run the test.


collapse all

This example shows how to specify model coverage report properties when running a Simulink® Test™ test file with MATLAB® Unit Test.

1. Import classes for the example.

import matlab.unittest.TestSuite
import matlab.unittest.TestRunner
import sltest.plugins.ModelCoveragePlugin
import sltest.plugins.coverage.ModelCoverageReport

2. Create a test suite and test runner.

Create a MATLAB Unit Test suite from AutopilotTestFile. Also create a test runner.

ste = testsuite('RollRefTest_cov.mldatx');
trn = TestRunner.withNoPlugins;

3. Specify the report location and name.

Create a subfolder in the current folder, and create a ModelCoverageReport object specifying the new folder.

path = './exReports/coverage';
mcr = ModelCoverageReport(path,'ReportName','RollRefCov');

4. Create a Model Coverage Plugin.

Use the Producing property to specify the ModelCoverageReport when creating the plugin.

mc = ModelCoveragePlugin('Producing',mcr)
mc = 
  ModelCoveragePlugin with properties:

    RecordModelReferenceCoverage: '<default>'
                 MetricsSettings: '<default>'
             ScopeToRequirements: 0

5. Add the coverage plugin to the test runner, and run the test.


% Turn off the command line warnings.
warning off Stateflow:cdr:VerifyDangerousComparison
warning off Stateflow:Runtime:TestVerificationFailed

Coverage Report for RollAutopilotRevised/Roll Reference
ans = 
  TestResult with properties:

          Name: 'RollRefTest_cov > Logged Data and Coverage/RollReference Timeseries Input'
        Passed: 1
        Failed: 0
    Incomplete: 0
      Duration: 7.2069
       Details: [1x1 struct]

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

Cleanup. Remove temporary folder and clear variables. Enable warnings.

warning on Stateflow:cdr:VerifyDangerousComparison
warning on Stateflow:Runtime:TestVerificationFailed


Version History

Introduced in R2018b

expand all