Main Content

Link Test Cases to Requirements

If you have Simulink® Test™ and Requirements Toolbox™, you can link your requirements to test cases in the Test Manager. Linking requirements to tests allows you to verify that the implementation of the requirement behaves as expected. You can use the requirement verification status to track verification progress. For more information, see Review Requirements Verification Status.

Link a Test Case to a Requirement Example

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 include the results in the Requirements Editor.

To link a requirement to a test case, open the project, CruiseRequirementsExample. Then, open the crs_controller model.


Load the test files that contain the tests you want to link.

  1. From the model, open the Test Manager. In the Apps tab, click Simulink Test. In the Tests tab, click Simulink Test Manager.

  2. In the Test Manager, open the DriverSwRequest_Tests.mldatx and crs_controller_tests.mldatx test files. In the File section, click Open. Load the test files in the CruiseRequirementsExample\tests folder.

The test files contain the test cases for several of the requirements in the crs_controller model. Most of these test cases already link to requirements.

In this example, you link the Increment button hold test to a requirement. In the left pane, click DriverSWRequest_Tests > Unit test for DriverSwRequest > Increment button hold. In the model, open the Requirements Editor. In the Apps tab, in the Apps section, click Requirements Editor. Click Show Requirements. The Requirements Editor displays two requirement sets, crs_req_func_spec, and crs_req_safety_spec.

In this example, you do not test the requirements in crs_req_safety_spec, and you must load another requirement set to load the tested requirements. To close the crs_req_safety_spec requirement set, select crs_req_safety_spec and, in the File section, click Close. In the File section, click Open. In CruiseRequirementsExample\documents, open the file crs_req.slreqx. The Requirements Editor updates the loaded requirements.

Link the requirement to the test case. Expand the crs_req_func_spec requirement set and expand the requirement with the index 1. Select the requirement with the index 1.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.

You can view verification information for other requirements by selecting each requirement.

Run the linked tests. In the Test Manager, select the top node in the test hierarchy in the Test Browser pane that corresponds to each test file and click Run. The Results and Artifacts pane shows that 7 tests passed and 1 test failed in the DriverSwRequest_Tests test file, and that 4 of the tests passed in the crs_controller_tests test file. Expand the results of each test run, test file, and test suite. In the test results for DriverSwRequest_Tests, the Cancel button test failed.

To view the verification status associated with 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 of the display 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.3 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 details about 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.

Related Topics