For testing, a common model architecture uses a Signal Builder block to pass test inputs to a copy of a subsystem or a Model block referencing your main model. This architecture is an example of a standalone model designed for testing. Standalone test models include models created by Simulink® Coverage™, Simulink Design Verifier™, or custom models.
You can simplify testing by importing standalone models to your main model as Simulink Test™ test harnesses. Importing standalone models as test harnesses enables synchronization and management features, allowing you to
Iterate on your design, using model – harness synchronization to update your design.
Manage test harnesses, using the UI and programmatic interface.
Establish clear ownership of a test harness by a model, subsystem, or library being tested.
Before importing a model as a test harness, determine:
The model or component to associate the test harness with, which can be a top-level model, a subsystem, or a linked block.
The path to the model to be imported.
In the model to be imported, the component that is tested. In the new test harness, this component links to the owner component in the main model. You can synchronize design changes when the test harness is open or closed.
For example, this model uses a Signal Builder block
to pass test inputs to the
and a subsystem to verify the
Controller subsystem is tested.
You cannot create a test harness by importing
Models that have existing test harnesses
Models with unsaved changes. Save open models before importing.
When importing, consider the block type in the main model and the standalone model:
For a user-defined function block in the main model (such as an S-Function block), the tested component in the standalone model must be the same block type.
For a top-level main model, the tested component in the standalone model can be a Model block or a subsystem.
For a subsystem in the main model, the tested component in the standalone model can be a subsystem, Model block, or user-defined function block.
For a Model block in the main model, the tested component in the standalone model can be a Model block or a subsystem.
This example shows how to import a standalone test model to create a test harness in Simulink Test.
The Main Model and the Harness Model
The main model
sltestBasicCruiseControl is a simple cruise control system, with root import and output blocks.
The standalone test model contains a Signal Builder 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 and select Test Harness > Import for 'Controller'.
2. Set the following harness properties:
Clear Save test harness externally
Simulink model to import: Click Browse and select
Component under Test in imported model:
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.