Test Execution Order
When you execute a test, Simulink® Test™ opens the model to be tested, runs callback functions, closes the functions, and cleans up. If you have scripted iterations, they run before the model is loaded. The order in which tests execute depends on:
Whether you run a single test case or run a test suite containing one or more test cases
The number of models tested
The number of test cases
For serial simulations, the test cases run in the order they are listed in the Test Manager. To change the order in which test cases run in the Test Manager, drag and drop test cases into the desired order in the Test Browser pane. You cannot drag and drop test suites. If you run your simulations in parallel mode, the test cases might not run in the order displayed in the Test Manager.
If your test cases include callbacks, note that disp
and
fprintf
do not work in callbacks. To verify that the callbacks are
executed, use a MATLAB script that includes breakpoints in the callbacks.
Single Test Case on a Single Model
If you select a specific test case to run on a single model and the model is not open before the test runs, the execution order is:
Run test case
Pre-Load
callback.Run model
PreLoadFcn
callback.Load model.
Run model
PostLoadFcn
callback.Run test case
Post-Load
callback.Simulate model.
Run test case
Cleanup
callback.Run model
CloseFcn
callback.
If you run a test suite that contains a test case, the test suite Setup
callback runs before the first step and the test suite Cleanup
callback runs after the last step.
Multiple Test Cases on Multiple Models
If you run multiple test cases that run on separate models and the models are not open before the test runs, the execution order, which is shown for two test cases run on two models, is:
Run test case 1
Pre-Load
callback.Run model 1
PreLoadFcn
callback.Load model 1.
Run model 1
PostLoadFcn
callback.Run test case 2
Pre-Load
callback.Run model 2
PreLoadFcn
callback.Load model 2.
Run model 2
PostLoadFcn
callback.Run test case 1
Post-Load
callback.Simulate model 1 for test case 1.
Run test case 1
Cleanup
callback.Run test case 2
Post-Load
callback.Simulate model 2 for test case 2.
Run test case 2
Cleanup
callback.Run model 2
CloseFcn
callback.Run model 1
CloseFcn
callback.
If you run a test suite that includes test cases, the test suite
Setup
callback runs before the first step and the test suite
Cleanup
callback runs after the last step.
Multiple Test Cases in a Single Test Suite on a Single Model
If you run multiple test cases in a test suite on a single model and the model is not open before the test runs, the execution order, which is shown for two test cases, is:
Run test case 1
Pre-Load
callbackRun model
PreLoadFcn
callbackLoad model
Run model
PostLoadFcn
callbackRun test case 2
Pre-Load
callbackRun test case 1
Post-Load
callbackSimulate model
Run test case 1
Cleanup
callbackRun test case 2
Post-Load
callbackSimulate model
Run test case 2
Cleanup
callbackRun model
CloseFcn
callback
When a test suite runs multiple test cases on the same model, the model is kept open between
test executions. As a result, the code in the PreLoadFcn
callback for
the model is executed only when the model is opened for the first test case.
If the model is open before the test runs, the execution order, which is shown for two test cases, is:
Run test case 1
Pre-Load
callbackRun test case 2
Pre-Load
callbackRun test case 1
Post-Load
callbackSimulate model
Run test case 1
Cleanup
callbackRun test case 2
Post-Load
callbackSimulate model
Run test case 2
Cleanup
callback
Notice that the model PreLoadFcn
and PostLoadFcn
callbacks do not execute because the model is already loaded before the test runs. The
model CloseFcn
callback does not execute either because the model is
left open after test completion.
Multiple Test Cases in Multiple Test Suites on a Single Model
Suppose you have two test suites that each contain two test cases, such as:
Test suite 1
Test case 1-1
Test case 1-2
Test suite 2
Test case 2-1
Test case 2-2
the execution order of the callbacks is:
Run test suite 1
Setup
callback.Run test suite 2
Setup
callback.Run test case 1-1
Pre-Load
callback.Run test case 1-2
Pre-Load
callback.Run test case 2-1
Pre-Load
callback.Run test case 2-2
Pre-Load
callback.Run test case 1-1
PostLoad
callback.Simulate model.
Run test case 1-1
Cleanup
callback.Run test case 1-2
Post-Load
callback.Simulate model.
Run test case 1-2
Cleanup
callback.Run test suite 1
Cleanup
callback.Run test case 2-1
Post-Load
callback.Simulate model.
Run test case 2-1
Cleanup
callback.Run test case 2-2
Post-Load
callback.Simulate model.
Run test case 2-2
Cleanup
callback.Run test suite 2
Cleanup
callback.
Test Case with Parameter Overrides
For a test case with parameter overrides, the execution order is:
Run test case
Pre-Load
callback.Load model.
Read parameter overrides, which triggers a model update.
Run test case
Post-Load
callback.Simulate model.
Run test case
Cleanup
callback.Run model
CloseFcn
callback.