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.
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 Requirements Browser, select requirement
In the Test Manager, expand the test file and select the Safety Tests test case. Expand the Requirements section.
In the Requirements section, select Add > Link to Selected Requirement.
The requirements browser displays the verification-type link.
Also add a link for item
The test case uses a test harness
the test harness, a test sequence sets the input conditions and checks the model
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
verify(engaged == false,... 'verify:limit',... 'system must disengage when limit exceeded')
Run the test case. In the Test Manager toolstrip, click Run.
When the test finishes, expand the Verify Statements
results. The Test Manager results show that both assessments pass, and the plot
shows the detailed results of each
In the Requirements Browser, right-click a requirement and select Refresh Verification Status to show the passing test results for each requirement.
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.
For the Template File, select the
ReportTemplate.dotx file in the
documents project folder.
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.