Perform Functional Testing and Analyze Test Coverage
Functional testing begins with building test cases based on requirements. These tests cover key aspects of your design and verify that individual model components meet requirements. Test cases made for functional testing include inputs, expected outputs, and acceptance criteria. Additionally, if you store your functional test cases in test suites, you can run functional tests systematically.
You can also run regression testing and measure different levels of coverage to further refine your tests. To check for regression, you add baseline criteria to the test cases and compare the model outputs to a set of baseline data. You can then do coverage measurement on your model to identify the extent to which the tests exercised the model and identify if you need to add tests or requirements to meet your coverage targets.
This example shows how to perform requirements-based tests for a cruise control model. In this example, you:
Run the tests.
Determine test coverage by using Simulink® Coverage™.
Increase coverage by generating additional tests using Simulink Design Verifier™.
Report the results.
Open the Test Harness and Model
Open the example project:
openExample("shared_vnv/CruiseControlVerificationProjectExample"); pr = openProject("SimulinkVerificationCruise");
Open the model and the test harness.
open_system("simulinkCruiseAddReqExample"); sltest.harness.open("simulinkCruiseAddReqExample","SafetyTest_Harness1")
Open the test file
slReqTests.mldatx
in the Simulink Test Manager.pf = fullfile(pr.RootFolder,"tests","slReqTests.mldatx"); tf = sltest.testmanager.TestFile(pf); sltest.testmanager.view
In the test harness, open the Test Sequence block. The sequence verifies system disengagement when either:
The brake pedal is pressed.
The speed exceeds a limit.
Measure Model Coverage
In the Simulink Test Manager, select the
slReqTests
test file.To enable coverage collection, in the right pane, expand Coverage Settings, then expand Coverage to Collect:
Select Record coverage for referenced models.
Select Decision, Condition, and MCDC.
On the Test Manager toolstrip, click Run.
After the test completes, select Results. The test achieves 50% decision coverage, 41% condition coverage, and 25% MCDC coverage.
Generate Tests to Increase Model Coverage
Use Simulink Design Verifier to generate additional tests to increase model coverage.
In Results and Artifacts, select the
slReqTests
test file and, in the right pane, open the Aggregated Coverage Results section.Right-click the test results and select Add Tests for Missing Coverage.
Set Harness to
Create a new harness
.Click OK. The model being tested must either be on the MATLAB® path or in the working folder.
To execute the updated test suite, on the Test Manager toolstrip, click Run. The test results include coverage for the combined test case inputs and achieve increased model coverage.
See Also
sltest.testmanager.addTestsForMissingCoverage
(Simulink Test) | sltest.testmanager.TestOptions
(Simulink Test)
Related Topics
- Link to Requirements (Simulink Test)
- Verify Model Simulation by Using When Decomposition (Simulink Test)
- Compare Model Output to Baseline Data (Simulink Test)
- Generate Test Cases for Model Decision Coverage (Simulink Design Verifier)
- Increase Test Coverage for a Model (Simulink Test)