Documentation

Perform Functional Testing and Analyze Test Coverage

  • Products Used
  • Simulink® Test™, Simulink Coverage™ , Simulink Design Verifier™, Simulink Report Generator™

Functional Testing and Coverage Analysis Overview

Functional testing starts with building test cases based on requirements. These tests can cover key aspects of your design and verify that individual model components meet requirements. Test cases include inputs, expected outputs, and acceptance criteria.

By collecting individual test cases within test suites, you can run functional tests systematically. To check for regression, add baseline criteria to the test cases and test the model regularly. Coverage measurement reflects the extent to which these tests have fully exercised the model. Coverage measurement also helps you to add tests and requirements to meet coverage targets.

Incrementally Increase Test Coverage Using Test Case Generation

This example shows a functional testing-based testing workflow for a cruise control model. You start with a model that has tests linked to an external requirements document, analyze the model for coverage in Simulink Coverage, incrementally increase coverage with Simulink Design Verifier, and report the results.

Explore the Test Harness and the Model

  1. Create a copy of the project in a working folder. At the command line, enter:

    slVerificationCruiseStart

  2. Open the model and the test harness. At the command line, enter:

    open_system simulinkCruiseAddReqExample
    sltest.harness.open('simulinkCruiseAddReqExample','SafetyTest_Harness1')
  3. Load the test suite from Test Model Against Requirements and Report Results (Simulink Test). At the command line, enter:

    open slReqTests.mldatx

  4. Open the test sequence block. The sequence tests:

    • That the system disengages when the brake pedal is pressed

    • That the system disengages when the speed exceeds a limit

    Some test sequence steps are linked to a requirements document simulinkCruiseChartReqs.docx.

Measure Model Coverage

  1. In the test manager, enable coverage collection for the test case.

    1. Open the test manager. In the Simulink menu, click Analysis > Test Manager.

    2. In the Test Browser, click the slReqTests test file.

    3. Expand Coverage Settings.

    4. Under COVERAGE TO COLLECT, select Record coverage for referenced models.

    5. Under COVERAGE METRICS, select Decision, Condition, and MCDC.

  2. Run the test. On the test manager toolstrip, click Run.

  3. When the test finishes, in the Test Manager, navigate to the test case. The aggregated coverage results show that the example model achieves 50% decision coverage, 41% condition coverage, and 25% MCDC coverage.

Generate Tests to Increase Model Coverage

  1. Use Simulink Design Verifier to generate additional tests to increase model coverage. Select the test case in the Results and Artifacts and open the aggregated coverage results section.

  2. Select the test results from the previous section and then click Add Tests for Missing Coverage.

    The Add Tests for Missing Coverage options open.

  3. Under Harness, choose Create a new harness.

  4. Click OK to add tests to the test suite using Simulink Design Verifier.

  5. Run the updated test suite. On the test manager toolstrip, click Run. The test results include coverage for the combined test case inputs, achieving increased model coverage.

Related Topics

Was this topic helpful?