Contenido principal

Create Test Harnesses from Standalone Models

You can use standalone models to verify your main model. You can create Simulink® Test™ test harnesses by importing your standalone test models. Importing standalone models enables synchronization and management features, which allow you to:

  • Design iteratively and synchronize changes between the model and test harness.

  • Manage test harnesses by using the UI and programmatic interfaces.

  • Define ownership of the test harness associated with the model, subsystem, or library under test.

For more information about model and test harness synchronization, see Synchronize Changes Between Test Harness and Model.

A common test model passes input signals to a copy of a subsystem or a Model block referencing your main model. Test models include models created by Simulink Coverage™ and Simulink Design Verifier™.

Test Harness Import Workflow

Before importing a standalone model as a test harness, determine:

  • In the main model, the model or component to associate the test harness with.

  • The path to the standalone model.

  • The tested component in the standalone model.

    For example, this standalone model tests the Controller subsystem. The model passes Inputs to Controller. Safety Properties verifies the Controller output.

    Simulink Test Basic Cruise Control Verification model

Component Compatibility for Test Harness Import

When you import a model as a test harness, the component in the main model must be compatible with the component in the standalone model.

In the main model, if the component is:

In the standalone model, the tested component must be:

A user-defined function block (e.g. an S-Function block)

The same block type

The top-level model

A Model block or a subsystem

A subsystem

A subsystem, Model block, or a user-defined function block

A Subsystem Reference block

Subsystem model

A Model block

A Model block or a subsystem

You cannot create a test harness by importing:

  • Libraries

  • Models that have existing test harnesses

  • Models with unsaved changes. Save open models before importing

Import a Standalone Model as a Test Harness

This example shows how to import a standalone test model to create a test harness in Simulink Test.

The main model sltestBasicCruiseControl is a cruise control system, with root import and output blocks.

The test model contains a Signal Editor block driving a copy of the Controller subsystem, with a subsystem verifying that the throttle output goes to 0 if the brake is applied for three consecutive time steps.

Create a Test Harness from the Standalone Model

1. In the main model, right-click the Controller subsystem. To add the Simulink Test app options to the menu, point to Select Apps and click the Simulink Test button. Then, in the Simulink Test app section, click the Import Test Harness button.

2. Set the following harness properties:

  • Name: VerificationSubsystemHarness

  • Simulink model to import: Click Browse and select sltestBasicCruiseControlHarnessModel in the MATLAB® examples/simulinktest directory.

  • Component under Test in imported model: Controller

3. Click OK.

A test harness is created from the standalone model, owned by the Controller subsystem in the main model. Click the badge to preview the test harness.

See Also

Topics