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.
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
models folder, 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®
slReqTests.mldatx from the
folder. The test file opens in the Test Manager.
Link the requirements to the test case.
In the Project window, open the Simulink
slReqTests.mldatx from the
folder. The test file opens in the Test Manager. Explore the test suite and
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
Also add a link for item
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:
BrakeTest sequence engages the cruise control, then
applies the brake. It includes the
verify(engaged == false,... 'verify:brake',... 'system must disengage when brake applied')
LimitTest sequence 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.
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.dotx file 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.