sltest.plugins.coverage.CoverageMetrics class

Package: sltest.plugins.coverage

Specify coverage metrics for tests run with MATLAB Unit Test framework

Description

Use the sltest.plugins.coverage.CoverageMetrics class to specify coverage metrics. Pass the coverage metrics object to the model coverage plugin object.

Creation

cmo = sltest.plugins.coverage.CoverageMetrics(Properties) creates a coverage metrics object with specified properties.

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

import sltest.plugins.coverage.CoverageMetrics
cmo = CoverageMetrics(Properties)

Properties

expand all

Enable or disable decision coverage collection.

Example: 'Decision',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable condition coverage collection.

Example: 'Condition',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable modified condition / decision coverage collection.

Example: 'MCDC',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable lookup table coverage collection.

Example: 'LookupTable',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable signal range coverage collection.

Example: 'SignalRange',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable signal size coverage collection.

Example: 'SignalSize',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable Simulink Design Verifier block coverage collection.

Example: 'SimulinkDesignVerifier',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable recording the number of times the block saturates on integer overflow.

Example: 'SaturationOnIntegerOverflow',true

Attributes:

SetAccess
public
GetAccess
public

Enable or disable relational boundary coverage.

Example: 'RelationalBoundary',true

Attributes:

SetAccess
public
GetAccess
public

Examples

collapse all

This example shows how to use MATLAB® Unit Test to collect coverage for tests run on a Simulink® model.

You run the tests in the AutopilotTestFile.mldatx test file while collecting modified condition/decision (MCDC) coverage.

1. Import the test runner and the plugins for the example.

import matlab.unittest.TestRunner
import sltest.plugins.ModelCoveragePlugin
import sltest.plugins.coverage.CoverageMetrics

2. Create the model coverage plugin object and the coverage metrics object. In this example, you use MCDC coverage and record coverage for referenced models.

mcdcMet = CoverageMetrics('Decision',false,'Condition',false,'MCDC',true);

covSettings = ModelCoveragePlugin('RecordModelReferenceCoverage',true,...
    'Collecting',mcdcMet);

3. Create a MATLAB® Unit Test test suite from the test file.

tf = sltest.testmanager.TestFile(fullfile(matlabroot,'toolbox','simulinktest',...
    'simulinktestdemos','AutopilotTestFile.mldatx'));
APSuite = testsuite(tf.FilePath);

4. Create the test runner without any plugins, then add the coverage plugin to the runner.

APRun = TestRunner.withNoPlugins();
addPlugin(APRun,covSettings);

5. Run the suite.

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

APResult = run(APRun,APSuite)
APResult = 
  TestResult with properties:

          Name: 'AutopilotTestFile > Basic Design Test Cases/Requirement 1.3 Test'
        Passed: 0
        Failed: 1
    Incomplete: 1
      Duration: 0.0269
       Details: [1x1 struct]

Totals:
   0 Passed, 1 Failed (rerun), 1 Incomplete.
   0.026932 seconds testing time.

6. You can open the link in the command-line output to view the coverage report.

Cleanup. Clear results and re-enable warnings.

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

sltest.testmanager.clearResults;
sltest.testmanager.clear;
sltest.testmanager.close;

Introduced in R2018a