Main Content


Enable model coverage collection for TestTask instance

Since R2024a


task = addModelCoverage(task,results)
task = addModelCoverage(___,Name=Value)


task = addModelCoverage(task,results) enables the test task specified by task to produce the coverage results in the specified model coverage results file. You must have a Simulink® Coverage™ license to use the addModelCoverage method. addModelCoverage is a method of the matlab.buildtool.tasks.TestTask class.

To use addModelCoverage, use a single command to create the TestTask and add the model coverage. When you create the matlab.buildtool.tasks.TestTask instance, specify the Simulink Test™ or MATLAB®-based Simulink tests. For example,

task = TestTask("myTestFolder").addModelCoverage...
   ("model-coverage/report.html", CoverageMetrics=...

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

Input Arguments

expand all

Test task to configure for model coverage collection, specified as a matlab.buildtool.tasks.TestTask object. The addModelCoverage method outputs an object that has model coverage collection enabled.

Model coverage results files, specified as a string vector, character vector, cell vector of character vectors, or a vector of objects. To specify the file format, include one of these file extensions with the file name:

  • .html — Produce an HTML model coverage report.

  • .xml — Produce model coverage results in Cobertura XML format.

The default format is HTML.

Example: "myModelCovReport.xml"

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.

Example: CoverageMetrics=["MCDC","SignalRange"]

Types of coverage to collect, specified as a string, character vector, or cell vector of character vectors that correspond to the properties of the sltest.plugins.coverage.CoverageMetrics class. If you specify more than one type of coverage, use a string vector or a cell vector of character vectors. If you do not specify CoverageMetrics, the TestTask output object includes the coverage metrics applied to the corresponding Simulink Test and MATLAB-based Simulink tests.

Example: CoverageMetrics=["MCDC","SignalRange"]

Whether to include referenced models in the model coverage analysis, specified as a numeric or logical 1 (true) or 0 (false).

Example: IncludeReferencedModels=false


expand all

To produce model coverage results for a TestTask object in your build file, use the addModelCoverage method.

This sample buildfile.m file produces MCDC and signal range coverage when you run the tests in myTestFolder, which is the setting of the Tests property of the TestTask class.

function plan = buildfile
   import matlab.buildtool.tasks.TestTask
   plan = buildplan();

   plan("test") = TestTask("myTestFolder").addModelCoverage...
     CoverageMetrics=["MCDC" "SignalRange"]);

Use the test task to run the test and produce a model coverage report for the models under test.

buildtool test

Version History

Introduced in R2024a