Since requirements specify behavior in response to particular conditions, you can build test cases (test inputs, expected outputs, and assessments) from the model requirements. Test cases reproduce specific conditions using test inputs, and assess the actual model output against the expected outputs. As you develop the model, build test files that check system behavior and link them to corresponding requirements. By defining these test cases in test files, you can periodically check your model and archive results to demonstrate model stability.
If you have a Simulink® Test™ and a Simulink Requirements™ license, you can link requirements to test harnesses, test sequences, and test cases. Before adding links, review Supported Requirements Document Types.
When you edit requirements links to the component under test, the links immediately synchronize between the test harness and the main model. Other changes to the component under test, such as adding a block, synchronize when you close the test harness. If you add a block to the component under test, close and reopen the harness to update the main model before adding a requirement link.
To view items with requirements links, on the Apps tab, under Model Verification, Validation, and Test, click Requirements Manager. In the Requirements tab, click Highlight Links .
In test sequences, you can link to test steps. To create a link, first find the model item, test case, or location in the document you want to link to. Right-click the test step, select Requirements, and add a link or open the link editor.
To highlight or remove the highlighting from test steps that have requirements links, toggle the requirements links highlighting button in the Test Sequence Editor toolstrip. Highlighting test steps also highlights the model block diagram.
If you use many test cases with a single test harness, link to each specific test case to distinguish which blocks and test steps apply to it. To link test steps or test harness blocks to test cases,
Open the test case in the Test Manager.
Highlight the test case in the test browser.
Right-click the block or test step, and select Requirements > Link to Current Test Case.
This example demonstrates adding requirements links to a test harness and test sequence. The model is a component of an autopilot roll control system. This example requires Simulink Test and Simulink Requirements.
Open the test file, the model, and the harness.
open AutopilotTestFile.mldatx, open_system RollAutopilotMdlRef, sltest.harness.open('RollAutopilotMdlRef/Roll Reference',... 'RollReference_Requirement1_3')
In the test harness, on the Apps tab, under Model Verification, Validation, and Test, click Requirements Manager. In the Requirements tab, click Highlight Links .
The test harness highlights the Test Sequence block, component under test, and Test Assessment block.
Add traceability to the Discrete Derivative block.
Right-click the Discrete Derivative block and select Requirements > Open Outgoing Links dialog.
In the Requirements tab, click New.
Enter the following to establish the link:
1.3 Roll Hold Reference
Click OK. The Discrete Derivative block highlights.
To trace to the requirements document, right-click the Discrete Derivative block, and select Requirements > DD Link. The requirements document opens in the editor and highlights the linked text.
Open the Test Sequence block. Add a
requirements link that links the
to the test case.
In the Test Manager, highlight
1.3 Test in the test browser.
InitializeTest step in the Test
Sequence Editor. Select Requirements > Link to Current Test Case.
When the requirements link is added, the Test Sequence Editor highlights the step.