Main Content

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

  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 2 Pre-Load callback.

  6. Run model 2 PreLoadFcn callback.

  7. Load model 2.

  8. Run model 2 PostLoadFcn callback.

  9. Run test case 1 Post-Load callback.

  10. Simulate model 1 for test case 1.

  11. Run test case 1 Cleanup 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 2 CloseFcn callback.

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

  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 2 Pre-Load callback

  6. Run test case 1 Post-Load callback

  7. Simulate model

  8. Run test case 1 Cleanup callback

  9. Run test case 2 Post-Load callback

  10. Simulate model

  11. Run test case 2 Cleanup callback

  12. Run 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:

  1. Run test case 1 Pre-Load callback

  2. Run test case 2 Pre-Load callback

  3. Run test case 1 Post-Load callback

  4. Simulate model

  5. Run test case 1 Cleanup 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 suite 2 Setup callback.

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

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

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

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

  7. Run test case 1-1 PostLoad callback.

  8. Simulate model.

  9. Run test case 1-1 Cleanup callback.

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

  11. Simulate model.

  12. Run test case 1-2 Cleanup callback.

  13. Run test suite 1 Cleanup callback.

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

  15. Simulate model.

  16. Run test case 2-1 Cleanup 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.