Main Content

Test Execution Order

When you execute a test, Simulink® Test™ opens the model to be tested, runs callback functions, closes the models, and cleans up. If you have scripted or table 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. Instead, use the ShowSimulationLogs property of sltest.testmanager.setpref. To verify that the callbacks are executed, use a MATLAB script that includes breakpoints in the callbacks.

For test execution order for real-time tests, see Test Models in Real Time.

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:

  1. Run test case Pre-Load callback.

  2. Run model PreLoadFcn callback.

  3. Load model.

  4. Run model PostLoadFcn callback.

  5. Run test case Post-Load callback.

  6. Simulate model.

  7. Run test case Cleanup callback.

  8. 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:

  1. Run test case 1 Pre-Load callback.

  2. Run model 1 PreLoadFcn callback.

  3. Load model 1.

  4. Run model 1 PostLoadFcn callback.

  5. Run test case 1 Post-Load callback.

  6. Simulate model 1 for test case 1.

  7. Run test case 1 Cleanup callback.

  8. Run test case 2 Pre-Load callback.

  9. Run model 2 PreLoadFcn callback.

  10. Load model 2.

  11. Run model 2 PostLoadFcn callback.

  12. Run test case 2 Post-Load callback.

  13. Simulate model 2 for test case 2.

  14. Run test case 2 Cleanup callback.

  15. Run model 1 CloseFcn callback.

  16. Run model 2 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.

The order in which models are closed using the CloseFcn might be different than the order in which they were opened or run. In the above example, steps 15 and 16 might be switched.

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:

  1. Run test case 1 Pre-Load callback.

  2. Run model PreLoadFcn callback.

  3. Load model.

  4. Run model PostLoadFcn callback.

  5. Run test case 1 Post-Load callback.

  6. Simulate model.

  7. Run test case 1 Cleanup callback.

  8. Run test case 2 Pre-Load callback.

  9. Run test case 2 Post-Load callback.

  10. Simulate model.

  11. Run test case 2 Cleanup callback.

  12. Run model CloseFcn callback.

If the model is open before the test runs, the execution order, which is shown for two test cases, is:

  1. Run test case 1 Pre-Load callback

  2. Run test case 1 Post-Load callback

  3. Simulate model

  4. Run test case 1 Cleanup callback

  5. Run test case 2 Pre-Load callback

  6. Run test case 2 Post-Load callback

  7. Simulate model

  8. 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:

  1. Run test suite 1 Setup callback.

  2. Run test case 1-1 Pre-Load callback.

  3. Run test case 1-1 PostLoad callback.

  4. Simulate model.

  5. Run test case 1-1 Cleanup callback.

  6. Run test case 1-2 Pre-Load callback.

  7. Run test case 1-2 Post-Load callback.

  8. Simulate model.

  9. Run test case 1-2 Cleanup callback.

  10. Run test suite 1 Cleanup callback.

  11. Run test suite 2 Setup callback.

  12. Run test case 2-1 Pre-Load callback.

  13. Run test case 2-1 Post-Load callback.

  14. Simulate model.

  15. Run test case 2-1 Cleanup callback.

  16. Run test case 2-2 Pre-Load callback.

  17. Run test case 2-2 Post-Load callback.

  18. Simulate model.

  19. Run test case 2-2 Cleanup callback.

  20. Run test suite 2 Cleanup callback.

Test Case with Parameter Overrides

For a test case with parameter overrides, the execution order is:

  1. Run test case Pre-Load callback.

  2. Load model.

  3. Read parameter overrides, which triggers a model update.

  4. Run test case Post-Load callback.

  5. Simulate model.

  6. Run test case Cleanup callback.

  7. Run model CloseFcn callback.