Main Content

Use Test Sequence Scenarios in the Test Sequence Editor and Test Manager

This example shows how to create and use scenarios in the Test Sequence Editor. Scenarios let you include multiple test sequences in a Test Sequence block. If your test harness includes more than one Test Sequence block, you can move each test sequence to a scenario in a single Test Sequence block.

The example also shows how to use the Test Manager to set up and use iterations to run multiple scenarios in a single test case.

Open the Model and Test Harness

Open the HeatPumpScenario model, ScenarioTest harness, and Test Sequence Editor.

open_system('ScenarioTest/Test Sequence')

Enable Scenarios

In the panel on the left side of the Test Sequence Editor, switch to the Scenarios tab and click Use Scenarios.

In the Start Using Scenarios dialog box, click OK, which confirms that when you switch to scenario mode you cannot revert the Test Sequence block to non-scenario mode. The existing steps and transitions are moved into a tab named Scenario_1.

Add a New Scenario

To add a new scenario, in the Scenarios tab, click the plus sign next to Scenario List. Alternatively, click on the plus sign next to the header of the Scenario_1 tab. The new scenario is named Scenario_2.

Duplicate a Scenario

To start from an existing scenario, you can duplicate it. Go to the Scenarios tab. Point to Scenario_1 in the Scenario List to display the Duplicate scenario button. Click the Duplicate scenario button to add a new scenario named Scenario_3, which has the same content as Scenario_1.

Edit the Steps and Transitions

Modify Scenario_3 to change the transition of the Test_signals step to Troom_in >= 78.

Delete the Unused Scenario

In the Scenarios tab on the sidebar, hover over Scenario_2 in the Scenario List to display the Delete Scenario button. Click the Delete Scenario button and then click OK in the dialog box to delete Scenario_2.

The name of Scenario_3 does not change, but the scenario index shown in to the left of the scenario in the Scenario List changes to 2 because it is now the second scenario.

Activate Scenario

In the Scenario List sidebar, a black lightning bolt icon and a bolded Scenario name indicate that Scenario_1 is the currently active scenario. If you run the model, only the active scenario runs.

Change the active scenario to Scenario_3. Point to Scenario_3 in the Scenario List to display the activate button, which is a grey lightning bolt. Click the lightning bolt to make Scenario_3 the active scenario.

Another way to control which scenario is active is from the command line. See the Alternative Way to Control Active Scenario section below.

Run the Active Scenario

Run the model and you will see that Scenario_3 runs. The active scenario runs regardless of which scenario tab is currently displayed. If you switch the display to Scenario_1 and click Run, the displayed scenario switches to the active Scenario_3 and runs that scenario.

Alternative Way to Control Active Scenario

Instead of setting the active scenario from within the Test Sequence Editor, you can use a variable in the base workspace, model workspace, or a data dictionary to control the active scenario. To activate a scenario, set the variable value to the index of the scenario.

1. In the Test Sequence Editor Scenarios tab, go to the Scenario Parameter section.

2. Enable Control active scenario from workspace. The previously active scenario is deactivated. When you control the active scenario using a workspace variable, the Test Sequence Editor does not know which scenario is active until you click Run.

3. For this example, in the base workspace, create a variable named Active_Scenario_Index and set it to activate the first scenario, Scenario_1, by entering: Active_Scenario_Index = Simulink.Parameter(1);

4. Return to the Test Sequence Editor and click Run. Scenario_1 runs.

Instead of using Active_Scenario_Index as the name of the variable, you can specify a different name.

1. For this example, in the Test Sequence Editor, in the Scenario Parameter section, click on Active_Scenario_Index and enter a new name, such as ChangeScenario.

2. In the base workspace, create a variable named ChangeScenario. Set it to the desired scenario index, such as 1, by entering: ChangeScenario = Simulink.Parameter(1);.

3. Return to the Test Sequence Editor and click Run. Scenario_1 runs.

Use Iterations to Run Multiple Scenarios in a Test Case

You can run multiple scenarios in a test case by using iterations. This section describes scenarios in iterations using the Test Manager.

1. In the Test Manager, create a test file, test suite, and simulation test case.

2. In the System Under Test section, set the Model to HeatPumpScenario and the Harness to ScenarioTest.

3. In the Inputs section, click the Refresh icon next to the Test Sequence Block field to populate it with paths to Test Sequence blocks in the harness.

4. Set Test Sequence Block to the ScenarioTest/Test Sequence block, which has the scenarios to use in the iterations.

5. Click the Refresh icon next to the Override with Scenario field to populate it with the scenarios in the selected block.

6. Set Override with Scenario to Scenario_1, which set that scenario as the default for all iterations. This scenario overrides the active scenario in the Test Sequence block. In the Iterations section, you can change this default scenario to another scenario for each iteration.

If you do not select a scenario, the active scenario in the Test Sequence block is used as the default.

7. In the Iterations section, expand Table Iterations, click the plus sign in the upper right of the table and select Test Sequence Scenario to add that column to the table.

8. Click Add at the bottom of the Table Iterations to add the individual iterations. The Test Sequence Scenario column for each iteration shows the default scenario. In this case, it shows [Default] Scenario_1.

Alternatively, click Auto Generate and select Test Sequence Scenario to generate an iteration for each scenario in the selected Test Sequence block. In the Test Sequence Scenario column, each iteration is assigned a separate iteration.

9. In the Test Sequence Scenario column of an iteration, click the scenario name to view a list of available scenarios. Select a different scenario from the default for one of the iterations.

10. Run the test.

See Also

Related Topics