Collect Coverage in Tests
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
Test™ Test Manager or
sltest.testmanager.CoverageSettings, you must
Coverage™ installed. 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 Simulink
Requirements™ installed, you can also use the Test Manager to verify that coverage results
are traced to specific requirements.
Coverage is not supported for Software-in-the-Loop (SIL) or Processor-in-the-Loop (PIL) blocks.
Set Up Coverage Collection Using the Test Manager
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 for the model specified as the System Under Test in each test case. Select Record coverage for referenced models to collect coverage for models that referenced from within the specified system under test. The selected coverage settings propagate from the test file to the test suites and test cases in the test file.
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.
Run the test. Coverage is collected for the test suites and test cases in the test file.
To remove individual test suites or test cases from collecting coverage data, select the test suite or test case and change its coverage settings.
View and Filter Coverage Results in the Test Manager
View Aggregated Coverage Results and Metrics
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.
Scoping Coverage for Requirements-Based Tests
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.
Trace Coverage Results to the Model
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.
Create a Coverage Report
To create a report of the coverage for a model, click the arrow in the Report column of the Aggregated Coverage Results table.
Coverage Filtering Using the Test Manager
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, which are shown for a result set, update automatically. You do not have to resimulate your model. For more information, see Coverage Filtering (Simulink Coverage).
To view the filtered coverage results, select a result set (that is, a Results item) in the Results and Artifacts pane.
From the Test Manager, you can:
Add or remove an existing coverage filter file — In the Test Browser pane, select the test file and expand the Coverage Settings section. 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 Excludelink. 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.
View coverage results — Select a Results item in the Results and Artifacts pane and expand the Aggregated Coverage Results section.
For more information on coverage filters, rules, and files, see the Coverage Filtering topics in Analyze Coverage and View Results (Simulink Coverage).
For information on considerations when collecting coverage in a test harness, see Test Harness Considerations in Test Harness and Model Relationship.
- Analyze Coverage and View Results (Simulink Coverage)
- Model Objects That Receive Coverage (Simulink Coverage)
- Perform Functional Testing and Analyze Test Coverage
- Test Coverage for Requirements-Based Testing
- Assess Coverage Results from Requirements-Based Tests (Simulink Coverage)
- Trace Coverage Results to Requirements (Simulink Coverage)
- Requirements-Based Testing (Simulink Requirements)