Main Content

Test Model Against Requirements and Report Results

Establishing traceability between requirements and test cases helps you interpret the test results and see the extent to which your model verifies your requirements. You can establish traceability by linking a requirement to the elements that verify it, such as the test cases in the Test Manager, verify statements in a Test Sequence block, or model verification blocks. When you run tests, a pass/fail summary appears in your requirements set.

This example demonstrates how to test the requirements of a cruise control system against a model. You start with a requirements set, a model, and a test case. You add traceability between the tests and the safety requirements, run the test, summarize the verification status, and report the results.

The requirements testing process. You start with system requirements, develop the architecture, then develop the model. Then you develop test cases and functional requirements, run the tests, and update the requirements and tests as necessary. You then report the results.

In this example, you test of two requirements in the requirement set:

  • That the cruise control system transitions from engaged to disengaged when a braking event occurs

  • That the cruise control system transitions from engaged to disengaged when the current vehicle speed is outside the range of 20 mph to 90 mph

Display the Requirements

  1. Open the example project.

    openExample("shared_vnv/CruiseControlVerificationProjectExample");
    pr = openProject("SimulinkVerificationCruise");
  2. Open the simulinkCruiseAddReqExample model.

    open_system("simulinkCruiseAddReqExample");
  3. Display the requirements. Click the icon in the lower-right corner of the model canvas, and select Requirements. The Requirements pane opens.

  4. Display the verification and implementation status. Right-click the requirement set and select Verification Status and Implementation Status.

    Property Inspector and Requirements pane showing the implementation status for the model

Link Requirements to Tests

Link the requirements to the test case.

  1. In MATLAB®, in the Project pane, in the tests folder, open the Simulink® Test™ file slReqTests.mldatx. The test file opens in the Test Manager.

  2. In the model, click on requirement S 3.1.

  3. In the Test Manager, select the Safety Tests test case. In the right pane, in the Requirements section, click Add > Link to Selected Requirement. In the model, in the Property Inspector, the Verified by section indicates a link to the Safety Tests. In the Requirements pane, the yellow bars in the Verified column indicate that the linked tests have not been executed.

    Requirement dialog box showing linked tests to specific requirements

  4. Repeat the previous step to add a link for requirement S 3.4.

Run the Test

The test case uses a test harness named SafetyTest_Harness1. To open the test harness, click the icon in the lower-right corner of the model canvas and select SafetyTest_Harness1. In the test harness, open the Test Sequence block. The test sequence sets the input conditions and checks the model behavior:

  • The BrakeTest sequence engages the cruise control, then applies the brake. It includes this verify statement:

    verify(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 this verify statement:

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

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

  2. When the test finishes, review the results. In the Test Manager, the Results and Artifacts pane shows that both assessments pass. The plot provides the detailed results of each verify statement.

    Test results for verify statements

  3. Return to the model and click the Refresh button in the Requirements pane to refresh the requirements. The green bar in the Verified column indicates that the test case successfully verified requirements S 3.1 and S 3.4.

    Verified status for requirements

Report the Results

Create a report using a custom Microsoft® Word template.

  1. In the Test Manager, in the Results and Artifacts pane, right-click the test case name. Select Create Report.

  2. In the Create Test Result Report dialog box, set these options:

    • TitleSafetyTest

    • Results forAll Tests

    • File FormatDOCX

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

  4. Set Template File to the file ReportTemplate.dotx file in the documents project folder.

  5. Click Create.

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

External Websites