A test harness is a model block diagram that you can use to develop, refine, or debug a Simulink® model or component. In the main model, you associate a harness with a model component or the top-level model. The test harness contains a separate model workspace and configuration set, yet it persists with the main model and can be accessed via the model canvas.
You build the test harness model around the component under test, which links the harness to the main model. If you edit the component under test in the harness, the main model updates when you close the harness. You can generate a test harness for:
A model component, such as a subsystem. The test harness isolates the component, providing a separate simulation environment from the main model.
A top-level model. The component under test is a Model block referencing the main model.
When you associate a test harness with a model component, the harness model workspace contains copies of parameters associated with the component.
This example shows a test harness for a component that contains a Gain block. The harness model workspace contains a copy of the parameter g because g defines a part of the component.
The parameter h is the gain of a gain block in the harness, outside the component under test (CUT). h exists only in the harness model workspace.
When you associate a harness with the top level of the main model, the harness model workspace does not contain copies of parameters relevant to the component. The component under test is a Model block referencing the main model, and parameters remain in the main model workspace. In this example, the component under test references the main model, and the variable g exists in the main model workspace. The variable h is the value of the Gain block in the harness. It exists only in the harness model workspace.
Parameters in the test harness resolve to the most local workspace. Parameters resolve to the harness model workspace, then the system model workspace, then the base MATLAB® workspace.