Coverage refers to determining the testing completeness of models and generated code
by analyzing how much of the model has been exercised. To collect coverage using the
Simulink®
Test™ Test Manager or sltest.testmanager.CoverageSettings
, a
Simulink
Coverage™ license is required. Although you can set up and run test cases using only
Simulink
Coverage, Simulink Test provides additional test creation and test management
features. For tests with coverage collection turned on, the Test Manager includes the
coverage of each metric you choose to collect in the results. If you have a license for
Simulink
Requirements™, you can also use the Test Manager to verify that coverage results are
traced to specific requirements.
In the Test Manager, you can enable coverage and select the coverage metrics at the test file level. Test suites and test cases inherit the coverage settings from the test file. However, you can turn off coverage collection for individual test suites and test cases.
To set up the Test Manager to include coverage collection:
Create a test file and set up a test case for your model.
Select the test file and expand the Coverage Settings section. Under Coverage to Collect, select Record coverage for system under test to turn on coverage collection. You can also collect coverage for referenced models.
Optionally, to add or remove existing coverage filter files, click Add or Remove, respectively, in the Coverage Filters section and select the filter file. More than one filter file can be applied at the same time.
Select the coverage metrics to collect. For information on metrics, see Types of Model Coverage (Simulink Coverage) and Model Objects That Receive Coverage (Simulink Coverage).
Run the test. Coverage is collected for all test suites and test cases in the test file.
To remove individual test suites or test cases from collecting coverage data, select the suite or case and change its coverage settings.
After you collect coverage, use the Results and Artifacts pane in the Test Manager to view the results. Coverage results are reported in results sets. Select a Results item in the pane and expand the Aggregated Coverage Results section. The coverage percentage is shown for each metric and the colors summarize the coverage results.
Dark blue — Satisfied coverage
Red — Unsatisfied coverage
Light blue — Justified coverage
To aggregate results from different test files into a single Result Set, select the separate results in the Results and Artifacts list. Then, from the context menu, select Merge Coverage Results. A Results Set that contains the combined coverage results appears in the list.
For requirements-based design and testing, such as for compliance to DO-178B, enable Scope coverage results to linked requirements to check that your model design is executing the requirements and that the tests are verifying those requirements. Both Simulink Coverage and Simulink Requirements licenses are required. This option is available only if the results set contains more than one simulation, such as multiple test cases or iterations.
When the Scope coverage results to linked requirements check box is selected, coverage results include only tests that are directly linked to requirements and are explicitly tested. The aggregated results update automatically without having to resimulate the model. If you have tests that touch a model component but are not directly linked to a requirement, your aggregated coverage results percentages might decrease when you enable scoping. To obtain 100% coverage to your requirements, you might need to update your tests, add requirements links, or justify or exclude some items from coverage.
To navigate from the test coverage results in the Test Manager to the model, click the model name in the Aggregated Coverage Results table.
The model opens, and its Coverage Report opens in the Coverage Details pane of the model window. In this sample model, the model elements are red because they have less than 100% coverage.
Point to a model element to see a summary of its metrics and block execution.
Click a model element to scroll to its detailed coverage results information in the Coverage Details pane.
To create a report of the coverage for a model, click the arrow in the Report column of the Aggregated Coverage Results table.
Coverage filter rules specify one or more model objects or lines of generated code to exclude from coverage collection or for which you want to justify the coverage results. A set of coverage filter rules is contained in a filter file, which can be applied to the model or code being tested. You can apply more than one filter file to a test and also, reuse filter files for different models. When you apply a new or updated filter, the aggregated coverage results update automatically. You do not have to resimulate your model. For more information, see Coverage Filtering (Simulink Coverage).
From the Test Manager, you can:
Add or remove an existing coverage filter file — Click Add or Remove at the bottom of the Coverage Filters or Applied Coverage Filters table and select the coverage filter file to add or remove, respectively. More than one coverage filter file can be applied to the coverage results.
Edit or create a filter file, define a filter rule, and justify or
exclude coverage — From a Coverage Report or the
Coverage Details pane of a model, open the
Simulink
Coverage Filter Editor by clicking on a justify icon or a
Justify or
Exclude
link. When the Filter Editor is open, the Test
Manager is locked. When you close the Filter Editor, the Test Manager is
enabled and the results and applied filters list are updated with your
changes. For information on using the Filter Editor, see Creating and Using Coverage Filters (Simulink Coverage) and
Create, Edit, and View Coverage Filter Rules (Simulink Coverage).
Append currently applied coverage filters to the test file — Click Update Test File.
For more information on coverage filters, rules, and files, see the Coverage Filtering topics in Evaluate Coverage Results (Simulink Coverage).
For information on considerations when collecting coverage in a test harness, see Test Harness Considerations in Test Harness and Model Relationship.
sltest.testmanager.CoverageSettings