Main Content

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.

Video Walkthrough

For a walkthrough of the example, play the video.

Open Project Files

Open the CruiseRequirementsExample project, which contains requirements, models, and tests for an automobile cruise control system. Then, open the crs_controller model.

openProject("CruiseRequirementsExample");
open_system("models/crs_controller")

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.

The DriverSwRequest_Tests test file is shown in the Test Browser. Its single test suite and eight test cases are shown.

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.

The Requirements Editor shows the crs_req_func_spec requirement set. Its four top-level requirements and top-level justification are collapsed.

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 refresh_16.png.

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:

  1. In the Test Manager, click Resume button.

  2. In the Requirements Editor, select the requirement with the index 1.7.

  3. 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.

Requirement 1.7 is selected in the Requirements Editor. The Properties section is collapsed. Its two implementation links to Simulink blocks and verification link to the Resume button test are shown.

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.

The results of the test run are shown in the Results and Artifacts pane. Seven of the tests passed. The Cancel button test is the only failed test.

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.

The requirements verification status for the requirement set is displayed in the Requirements Editor. Requirement 1.7 is selected and the verification status bar is green, indicating that it is verified.

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.

Related Topics