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, on the Apps tab, under Model Verification, Validation, and Test, click Design Verifier. On the Tests tab, click Simulink Test Manager. In the Review Results section, click Load Earlier Results. 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 Editor: The inputs are in scenarios in a Signal Editor block inside the test harness. The Signal Editor block supports MAT-files that contain these inputs. You can edit these scenarios in the Signal Editor.

    • 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. Simulink Design Verifier saves a MAT data file that also includes parameter settings. You can view or override these settings in the Parameter Overrides section of the Test Manager.

    Note

    Another way to import test cases from Simulink Design Verifier is with the Create Test for Component wizard. For information, see Generate Tests for a Component.

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'));

    If you do not specify the full file path, as shown in this step, the model must be on the MATLAB path or in the current working folder.

  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 Editor

    • 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. Then double-click the Harness Inputs Signal Editor block source.

  8. In the Block Parameters: Harness Inputs dialog box, click Launch Signal Editor .

  9. To see the test inputs in the Signal Editor, expand a test case and select the inputs.

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

See Also

Related Topics