Main Content

addModelCoverage

Enable collect model coverage collection for Simulink tests

Syntax

addModelCoverage(runner)
addModelCoverage(runner,Name,Value)

Description

addModelCoverage(runner) enables the specified test runner to add model coverage to MATLAB-based Simulink tests and generates a coverage report. This method adds sltest.plugins.ModelCoveragePlugin to the test runner.

Note

For MATLAB-based Simulink tests, to include model coverage results in the Simulink Test Manager, you must also use addSimulinkTestResults.

addModelCoverage(runner,Name,Value) enables model coverage collection with additional options specified by one or more Name,Value pair arguments.

Input Arguments

expand all

Test runner, specified as a matlab.unittest.TestRunner object.

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: 'CollectMetrics',['MCDC','Decision']

Name of folder to export HTML coverage report, specified as a string or character vector.

Example: 'html-report','mytests/coverage/'

Path to export Cobertura coverage report, specified as a string or character vector. The report is saved to the specified file location and file name.

Example: 'cobertura','mytests/coverage/test1_coverage.xml'

Collect coverage for model references, specified as a logical true or false. If IncludeModelReference is true, the runner collects coverage for the main model and all referenced models.

Example: 'IncludeModelReference',true

Collect coverage for metrics, specified as an array of strings or an array of character vectors. For supported coverage metrics, see the sltest.plugins.coverage.CoverageMetrics properties.

Example: 'CollectMetrics',['MCDC','Decision']

Examples

expand all

This example shows how to enable collecting model coverage and specify metrics when using the test runner.

Before running this example, create a test file named myTests.m. The example creates a test suite for the file, and then creates a test runner with the 'textoutput' option to output status and diagnostics to the command line. Add addSimulinkTestResults to the test runner to enable pushing the results in the Test Manager and exporting the test results to a file named testmgr_results.mldatx

Before running this example, create a test file named myTests.m.The example creates a test suite for the file, and then creates a test runner with the 'textoutput' option to output status and diagnostics to the command line. Add addModelCoverage to the test runner to enable collecting model coverage that uses MCDC and condition metrics, specify the folder name for the HTML report, and include referenced models. Add addSimulinkTestResults to the test runner to enable pushing the test results to the Test Manager.

suite = testsuite('myTests');
runner = testrunner('textoutput');
addModelCoverage(runner,...
   "CollectMetrics",["MCDC","Condition"],...
   "html-report","tests/cov/",
   "IncludeModelReference",true);
addSimulinkTestResults(runner);
run(runner,suite);

Version History

Introduced in R2021a