This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

Note: This page has been translated by MathWorks. Click here to see
To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Increase Coverage by Generating Test Inputs

Using Simulink® Design Verifier™, you can generate test inputs that replicate design errors, achieve test objectives, or meet coverage criteria. Simulink Test™ can create test cases that use test inputs and expected outputs from Simulink Design Verifier.

Overall Workflow

Test case generation follows this workflow.

  1. Choose an existing Simulink Design Verifier results file, or generate new results by analyzing your model.

    • If you use an existing results file, you can load results by either:

      • Using the Simulink Test command sltest.import.sldvData.

      • Using Simulink Design Verifier menu items. In the model, select Analysis > Design Verifier > Results > Load. Select the MAT file with the analysis results.

    • If you run a model analysis, the Simulink Design Verifier Results Summary window appears after the analysis completes.

  2. In the results summary window, click Export test cases to Simulink Test.

  3. Enter the name of an existing or new test harness.

  4. Select a test harness source for the generated test inputs. You can select

    • Inport: The inputs are contained in the Simulink Design Verifier data file and mapped to Inport blocks in the test harness. The mapping is shown in the Inputs section of the test case. Using the Inport option allows you to map other inputs to the test harness Inport blocks, which can be useful for running multiple test cases or iterations using the same test harness.

    • Signal Builder: The inputs are contained in groups in a Signal Builder block inside the test harness. Using the Signal Builder option allows you to view the test inputs in the Signal Builder block editor.

  5. Select a new or existing test file, and enter names for the test file and test case.

  6. Click OK to export the test cases to Simulink Test. The test files and test cases are updated in the Test Manager.

Test Case Generation Example

This example shows how to generate test cases for a controller subsystem using Simulink Design Verifier, and export the test cases to a test file in Simulink Test. The example requires a Simulink Design Verifier license.

The model is a closed-loop heat pump system. The controller accepts the measured room temperature and set temperature inputs. The controller outputs a bus of three signals controlling the fan, heat pump, and the direction of the heat pump (heat or cool). The model contains a harness that tests heating and cooling scenarios.

  1. Open the model.

    open_system(fullfile(docroot,'toolbox','sltest','examples',...
    'sltestTestCaseFromDVExample.slx'));
  2. Set the current working folder to a writable folder.

  3. In the model, generate tests for the Controller subsystem. Right-click the Controller block and select Design Verifier > Generate Tests for Subsystem.

    Simulink Design Verifier generates tests for the component.

  4. In the results summary window, click Export test cases to Simulink Test.

  5. In the Export Design Verifier Test Cases dialog box, enter:

    • Test Harness: TestHarness1

    • Harness Source: Signal Builder

    • Select Use a new test file

    • Test File: ./TestFile_GeneratedTests.mldatx

    • Test Case: <Create a new test case>

  6. Click OK.

    A new test file is created in the working folder, and a test harness is added to the main model, owned by the Controller subsystem. Click the harness badge to preview the new test harness.

  7. Click the TestHarness1 thumbnail to open the harness, and double-click the Signal Builder block source to see the generated inputs.

  8. In the Test Manager, the new test case displays the system under test, and the test harness containing the generated inputs in the Signal Builder source. Expand the Iterations section to see the iterations corresponding to the signal builder groups.

See Also