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 and Test Case

  1. 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',...
  2. In the project models folder, open the simulinkCruiseAddReqExample.slx model.

  3. 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.

  4. Expand the requirements information to include verification and implementation status. Right-click a requirement and select Verification Status and Implementation Status.

  5. Open the Simulink® Test™ file slReqTests.mldatx from the tests folder. The test file opens in the Test Manager.

Link Requirements to Tests

Link the requirements to the test case.

  1. In the Requirements Browser, select requirement S 3.1.

  2. In the Test Manager, expand the test file and select the Safety Tests test case. Expand the Requirements section.

  3. In the Requirements section, select Add > Link to Selected Requirement.

    The requirements browser displays the verification-type link.

  4. Also add a link for item S 3.4.

Run the Test

  1. 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 the verify statement

      verify(engaged == false,...
          '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 the verify statement.

      verify(engaged == false,...
          'system must disengage when limit exceeded')

  2. Run the test case. In the Test Manager toolstrip, click Run.

  3. 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 verify statement.

  4. In the Requirements Browser, right-click a requirement and select Refresh Verification Status to show the passing test results for each requirement.

Report the Results

  1. Create a report using a custom Microsoft® Word template.

    1. From the Test Manager results, right-click the test case name. Select Create Report.

    2. 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.

    3. For the Template File, select the ReportTemplate.dotx file in the documents project folder.

    4. Enter a file name and select a location for the report.

    5. Click Create.

  2. Review the report.

    1. In the Test Case Requirements section, click the link to trace to the requirements document.

    2. The Verify Result section contains details of the two assessments in the test, and links to the simulation output.

Related Topics