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, verify
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
Open the example project.
openExample("shared_vnv/CruiseControlVerificationProjectExample"); pr = openProject("SimulinkVerificationCruise");
In the
models
folder, open thesimulinkCruiseAddReqExample
model.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.
Display the verification and implementation status. Right-click a requirement and select Verification Status and Implementation Status.
In the Project window, open the Simulink® Test™ file
slReqTests.mldatx
from thetests
folder. 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
slReqTests.mldatx
from thetests
folder. The test file opens in the Test Manager. Explore the test suite and selectSafety Tests
.Return to the model. Right-click on requirement
S 3.1
and select Link from Selected Test Case.A link to the
Safety Tests
test 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
S 3.4
.
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:
The
BrakeTest
sequence engages the cruise control, then applies the brake. It includes theverify
statementverify(engaged == false,... 'verify:brake',... 'system must disengage when brake applied')
The
LimitTest
sequence engages the cruise control, then ramps up the vehicle speed until it exceeds the upper limit. It includes theverify
statement.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
verify
statement.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:
Title —
SafetyTest
Results for —
All Tests
File Format —
DOCX
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.dotx
file in the documents project folder.Click Create.
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.
Related Topics
- Link to Requirements (Simulink Test)
- Validate Requirements Links in a Model (Requirements Toolbox)
- Customize Requirements Traceability Report for Model (Requirements Toolbox)