Increase Test Coverage for a Model
Increase test coverage by generating test inputs.
If your tests achieve incomplete model coverage, you can increase coverage by generating test inputs using Simulink® Design Verifier™. This example shows how to increase test coverage beyond an initial test case. You measure initial coverage of a test case. Then, you generate new test cases, add them to the test suite, run the tests, and review aggregate coverage.
This example uses Simulink Design Verifier and Simulink® Coverage™.
This example tests a component of an autopilot system using a test harness. Time series data from the base workspace is mapped to root inports in the test harness. The test file is configured to collect coverage.
The example workflow is:
Measure model coverage of the initial test case.
Generate additional tests to achieve greater coverage.
Add the new test cases to the test file.
Run all test cases and review aggregate coverage.
Paths and Example Files
Set paths and filenames for the example.
rollModel = 'RollAutopilotRevised'; testHarness = 'RollReference_LoggedDataTest'; testFile = 'RollRefTest.mldatx';
Run the Initial Test and Review Coverage
1. Ensure the working folder is writable.
2. Open the test file.
3. Run the test. In the Test Browser, highlight the Logged Data and Coverage test suite. Click Run.
4. After the test completes, in the test results, expand the Coverage Results section. The test achieves partial coverage for the
Roll Reference subsystem.
Decision coverage: 80%
Condition coverage: 70%
Generate Tests to Increase Model Coverage
Generate additional tests for missing coverage.
1. Below the coverage result, click Add Tests for Missing Coverage.
2. In the Add Tests for Missing Coverage dialog box, set these options:
RollReference_LoggedDataTest. This maps the new test inputs to the existing test harness.
Create a new test case. This creates a new test case with the generated test inputs.
Baseline Test. This gives the option to capture baseline data output from the model for the generated tests.
RollRefTest. This re-uses the existing test file.
3. Click OK. A dialog box shows progress of the test case generation. When test case generation is complete, a new test case appears in the Test Manager.
Run the New Test Case
1. Drag and Drop the new test case into the Logged Data and Coverage test suite.
2. Run the Logged Data and Coverage test suite again.
3. When simulation completes, in the Results and Artifacts section, select the result set and expand the Aggregated Coverage Results. The test suite achieves complete coverage:
Clear variables and test results, and close the model.
clear reqDoc rollModel testFile testHarness topModel; sltest.testmanager.clearResults; sltest.testmanager.close; close_system('RollAutopilotRevised',0);