Requirements are the basis for your system architecture, algorithm, and test plan. Traceability between requirements documents, model, code, and tests helps you document relationships, manage design changes, and interpret test results. Required model properties and test objectives enable targeted design analysis and test case generation for specific scenarios. You can evaluate your design and identify incomplete or missing requirements with ad-hoc testing, using simulated user interfaces for your model. Also, you can use rapid prototyping to validate requirements, and connect to physical or simulated environments to test your algorithm. Update the design, adding requirements and requirements links as necessary.
This example shows a requirements-based testing workflow for a cruise control model. You start with a model that has traceability to an external requirements document. You add a test to evaluate two safety requirements, checking that the cruise control disengages when the system reaches certain conditions. You add traceability to this test, run the test, and report the results.
Create a copy of the project in a working folder. Enter
Open the model and the test harness. On the command line, enter
open_system simulinkCruiseAddReqExample sltest.harness.open('simulinkCruiseAddReqExample','SafetyTest_Harness1')
Open the Test Sequence block.
BrakeTest sequence tests that
the system disengages when the brake pedal is pressed. It includes
verify(engaged == false,... 'verify:brake',... 'system must disengage when brake applied')
LimitTest sequence tests that
the system disengages when the speed exceeds a limit. It includes
verify(engaged == false,... 'verify:limit',... 'system must disengage when limit exceeded')
Open the requirements document. In the Simulink Project window, expand the documents folder and open simulinkCruiseChartReqs.docx.
Add links between the test steps and the requirements document.
In the requirements document, highlight item 3.1, “Vehicle braking will transition system to disengaged (inactive) when engaged (active)”
With item 3.1 highlighted, in the test sequence, right-click
BrakeTest step. Select Requirements
traceability > Link to Selection in Word.
In the requirements document, highlight item 3.4, “Transition to disengaged (inactive) when vehicle speed is outside the limits of 20 mph to 90 mph”
With item 3.4 highlighted, in the test sequence, right-click
LimitTest step. Select Requirements
traceability > Link to Selection in Word.
Save the requirements document and the model.
Create a test case in the Test Manager, and link the test case to the requirements section.
Open the Test Manager. In the Simulink menu, select Analysis > Test Manager.
In the Test Manager toolstrip, click New > Test File. Select the tests folder in the project, and enter a name for the test file. Click Save.
A new baseline test is created.
Under System Under Test, in the Model field, click the button to use the current model. The field displays the model name.
Expand the Test Harness section. From the drop-down menu, select the test harness name.
In the requirements document, highlight section 3.1.
In the test case, expand the Requirements section.
Click the arrow next to the Add button and select
to Selection in Word.
Use the same process to link the test case to section 3.4 in the requirements document.
Highlight the test case. In the Test Manager toolstrip, click Run.
When the test finishes, expand the Verify Statements results. The results show that both assessments pass, and the plot shows the detailed results of each statement.
Create a report using a custom Microsoft Word template.
In the Test Manager, right-click the test case name. Select Results: > Create Report.
In the Create Test Result Report dialog box, set the options:
For the other options, keep the default selections.
For the Template File, select
ReportTemplate.dotx file in the documents project
Enter a file name and select a location for the report.
Review the report.
In the Test Case Requirements section, click the link to trace to the requirements document.
The Verify Result section contains details of the two assessments in the test, and links to the simulation output.