Main Content

addModelCoverage

Enable model coverage collection for TestTask instance

Since R2024a

Syntax

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

Description

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=...
   ["MCDC","SignalRange"]);

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 to produce, specified as one of these values:

For maximum flexibility in producing model coverage results, specify results as a CoverageFormat vector.

If you specify results as a value of type matlab.buildtool.io.File or convertible to matlab.buildtool.io.File, then specify formats by using file extensions:

  • .html — Produce an HTML model coverage report.

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

Example: "model-cov/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

Examples

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 the 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...
     ("model-coverage/report.html",...
     CoverageMetrics=["MCDC" "SignalRange"]);
end

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

buildtool test

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

This sample buildfile.m file produces a model coverage HTML report that has a custom report name.

function plan = buildfile
   import matlab.buildtool.tasks.TestTask
   import sltest.plugins.coverage.ModelCoverageReport
   
   plan = buildplan();

   reportFolder = fullfile("results","model-cov");
   mkdir(reportFolder);
   plan("test") = TestTask("myTestFolder").addModelCoverage...
    (ModelCoverageReport(reportFolder,ReportName="MyReport"...
    CoverageMetrics=["MCDC" "SignalRange"]));
end

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

expand all