Main Content

addModelCoverage

Enable model coverage collection for Simulink tests

Since R2021a

Syntax

addModelCoverage(runner)
addModelCoverage(runner,covformat,location)
addModelCoverage(___,Name,Value)

Description

addModelCoverage(runner) enables the specified test runner to add model coverage to MATLAB-based Simulink tests and generates a coverage report. The coverage format defaults to html-report. This method adds sltest.plugins.ModelCoveragePlugin to the test runner. addModelCoverage is a method of the matlab.unittest.TestRunner class.

addModelCoverage(runner,covformat,location) enables model coverage collection using the specified coverage format and saves the report in the specified location.

addModelCoverage(___,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.

Coverage report format, specified as either specified as a "cobertura" or "html-report". If you specify the coverage format, you must also specify the location.

Coverage report folder, specified as a string. You must specify the location if you specify the coverage format.

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

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"]

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 a cell array of character vectors. For supported coverage metrics, see the sltest.plugins.coverage.CoverageMetrics properties.

Example: 'CollectMetrics',["MCDC","Decision"] or '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 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. Also, 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

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

Version History

Introduced in R2021a