Test Model Against Requirements and Report Results
Requirements – Test Traceability Overview
Traceability between requirements and test cases helps you interpret test results and see the
extent to which your requirements are verified. You can link a requirement to elements
that help verify it, such as test cases in the Test Manager,
statements in a Test Sequence block, or Model Verification blocks in a
model. When you run tests, a pass/fail summary appears in your requirements set.
This example demonstrates a common requirements-based testing workflow for a cruise control model. You start with a requirements set, a model, and a test case. You add traceability between the tests and the safety requirements. You run the test, summarize the verification status, and report the results.
In this example, you conduct a simple test of two requirements in the set:
That the cruise control system transitions to disengaged from engaged when a braking event has occurred
That the cruise control system transitions to disengaged from engaged when the current vehicle speed is outside the range of 20 mph to 90 mph.
Display the Requirements
Create a copy of the project in a working folder. The project contains data, documents, models, and tests. Enter:
path = fullfile(matlabroot,'toolbox','shared','examples',... 'verification','src','cruise') run(fullfile(path,'slVerificationCruiseStart'))
In the project
modelsfolder, open the
Display the requirements. Click the icon in the lower-right corner of the model canvas, and select Requirements. The requirements appear below the model canvas.
Expand the requirements information to include verification and implementation status. Right-click a requirement and select Verification Status and Implementation Status.
In the Project window, open the Simulink® Test™ file
testsfolder. The test file opens in the Test Manager.
Link Requirements to Tests
Link the requirements to the test case.
In the Project window, open the Simulink Test file
testsfolder. The test file opens in the Test Manager. Explore the test suite and select
Return to the model. Right-click on requirement
S 3.1and select Link from Selected Test Case.
A link to the
Safety Teststest case is added to Verified by. The yellow bars in the Verified column indicate that the requirements are not verified.
Also add a link for item
Run the Test
The test case uses a test harness
SafetyTest_Harness1. In the test
harness, a test sequence sets the input conditions and checks the model behavior:
BrakeTestsequence engages the cruise control, then applies the brake. It includes the
verify(engaged == false,... 'verify:brake',... 'system must disengage when brake applied')
LimitTestsequence engages the cruise control, then ramps up the vehicle speed until it exceeds the upper limit. It includes the
verify(engaged == false,... 'verify:limit',... 'system must disengage when limit exceeded')
Return to the Test Manager. To run the test case, click Run.
When the test finishes, review the results. The Test Manager shows that both assessments pass and the plot provides the detailed results of each
Return to the model and refresh the Requirements. The green bar in the Verified column indicates that the requirement has been successfully verified.
Report the Results
Create a report using a custom Microsoft® Word template.
From the Test Manager results, right-click the test case name. Select Create Report.
In the Create Test Result Report dialog box, set the options:
Results for —
File Format —
For the other options, keep the default selections.
Enter a file name and select a location for the report.
For the Template File, select the
ReportTemplate.dotxfile in the documents project folder.
Review the report.
The Test Case Requirements section specifies the associated requirements
The Verify Result section contains details of the two assessments in the test, and links to the simulation output.
- Link to Requirements (Simulink Test)
- Validate Requirements Links in a Model (Requirements Toolbox)
- Customize Requirements Traceability Report for Model (Requirements Toolbox)