Link Test Cases to Requirements
If you have Simulink® Test™ and Requirements Toolbox™, you can link requirements to Simulink test cases. Linking requirements to tests allows you to use the requirement verification status to track your verification progress and verify that the implementation of the requirement behaves as expected.
This example shows how to link a test case to a requirement associated with a controller model of an automobile cruise control system. After you run the tests, you view the verification status in the Requirements Editor.
Open Project Files
CruiseRequirementsExample project, which contains requirements, models, and tests for an automobile cruise control system. Then, open the
In MATLAB®, open the test file that contains the tests you want to link. In the Project pane, in the
tests folder, open the
DriverSwRequest_Tests.mldatx test file in the Test Manager by right-clicking it and selecting Open. The test cases use the
crs_controller model as the system under test. Many of the test cases link to requirements in the
crs_req_func_spec requirement set.
In this example, you link a test case to a requirement in the
crs_req_func_spec requirement set. Open the Requirements Editor. In the Apps tab, select Requirements Editor.
Requirements Toolbox loaded the
crs_req_func_spec requirement set when you opened the
crs_controller model because the files have links between them. Ensure that the Requirements Editor analyzes the functional requirements for the verification links by clicking the Refresh button .
Link Requirements to Tests
Link the requirement that has the summary
Resume switch detection to the test case named
Resume button. To create the link:
In the Test Manager, click
In the Requirements Editor, select the requirement with the index
In the Links section, click Add Link > Link from Selected Test Case.
The link to the test case appears in the right pane, under Links.
Navigate to the test in the Test Manager by clicking the Resume button link.
Run Tests and View Verification Status
Run the tests in the
DriverSwRequest_Tests test file. In the Test Manager, in the Test Browser pane, select the
DriverSwRequest_Tests test file. Click Run.
The Results and Artifacts pane shows that seven tests passed and one test failed. In the Results and Artifacts pane, expand the results of the test run. The
Cancel button test failed.
View the requirements verification status in the Requirements Editor for the requirements linked to the tests. In the Requirements Editor, in the View section, click Columns > Verification Status. Some requirements do not have tests, and some requirements are fully verified. The bar in the Verified column shows the proportion of child requirements that have links to verification. The color indicates the proportion of tests that have passed, failed, or not run.
In this example, the verification status shows that the test that you linked to the requirement
1.7 passed, and the test linked to
Cancel Switch Detection failed. Some requirements are partially verified because the child requirements are not yet verified, such as requirement
1.8. To view a summary of the child requirements, point to the verification status bar of the parent requirement. Other requirements are unverified because they are not linked to a test case.
Navigate to the test result for requirement
1.7. Select the requirement and, in the right pane, under Links, next to
Resume button, click the Passed icon . The test result for the linked test opens in the Test Manager.