Main Content

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.

Requirements-based testing workflow

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

  1. Open the example project.

    pr = openProject("SimulinkVerificationCruise");
  2. In the models folder, open the simulinkCruiseAddReqExample 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. Display the verification and implementation status. Right-click a requirement and select Verification Status and Implementation Status.

    Property inspector and requirements implementation status for the model

  5. In the Project window, 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 Project window, open the Simulink Test file slReqTests.mldatx from the tests folder. The test file opens in the Test Manager. Explore the test suite and select Safety 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.

    Requirement dialog box showing linked tests to specific requirements

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

  1. Return to the Test Manager. To run the test case, click Run.

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

    Test results for verify statements

  3. Return to the model and refresh the Requirements. The green bar in the Verified column indicates that the requirement has been successfully verified.

    Verified status for requirements

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. Enter a file name and select a location for the report.

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

    5. Click Create.

  2. Review the report.

    1. The Test Case Requirements section specifies the associated requirements.

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

Related Topics

External Websites