Main Content

Test Sequence Basics

A test sequence consists of test steps arranged in a hierarchy. You can use a test sequence to define test inputs and to define how a test will progress in response to the simulation. A test step contains actions that execute at the beginning of the step. A test step can contain transitions that define when the step stops executing, and which test step executes next. Actions and transitions use MATLAB® as the action language. You create test sequences by using the Test Sequence block and the Test Sequence Editor. See Use Stateflow Chart for Test Harness Inputs and Scheduling.

Test Sequence Hierarchy

Test sequences defined in Test Sequence blocks can have parent steps and substeps. Substeps can activate only if the parent step is active. A group of steps in the same hierarchy level shares a common transition type. When you create a test step, the step becomes a transition option for other steps in the same group.

Test Sequence Scenarios

In a Test Sequence block, you can define multiple test sequences, which are called test sequence scenarios. By using scenarios, you can define distinct test sequences without having multiple Test Sequence blocks in your test harness. You can run test sequence scenarios in these ways:

  • Activate a single scenario from the Test Sequence Editor and run the model

  • Activate a single scenario using API commands and run the model

  • Control the active scenario with a workspace variable and run the model

  • Use a custom test script to loop through scenarios when running the model

  • Define iterations in the Test Manager to run more than one scenario in a single test case

For more information and examples of using test sequence scenarios, see Use Test Sequence Scenarios in the Test Sequence Editor and Test Manager and Programmatically Create and Run Test Sequence Scenarios.

Transition Types

Test sequences defined in Test Sequence blocks transition from one step to another in two ways:

  • Standard transition: You can define a sequence of actions that react to simulation conditions using a standard transition sequence. Standard transition sequences start with the first step and progress according to transition conditions and next steps. For a list of transitions, see Test Sequence and Assessment Syntax.

    This test sequence sets the value of Boolean outputs RedButtonIn and GreenButtonIn, with transitions happening after each step has been active for 1 sec.

    Test Sequence steps, transitions, and next steps

  • When decomposition: When decomposition sequences are analogous to switch statements in programming. Your sequence can act based on specific conditions occurring in your model. In a When decomposition sequence, steps activate based on a condition that you define after the step name. Transitions are not used between steps.

    This When decomposition contains three verify statements. Each verify statement is active when the signal gear is equal to a different value. For more information, see Assess a Model by Using When Decomposition.

    Test Sequence using when decomposition

Create a Basic Test Sequence

In this example, you use a Test Sequence block to create a simple test sequence for a transmission shift logic controller.

  1. Open the model. At the command line, enter

    openExample('TransmissionDownshiftTestSequence')
  2. Right-click the shift_controller subsystem and select Test Harness > Create for ‘shift_controller’.

  3. In the Create Test Harness dialog box, under Sources and Sinks:

    • Select Test Sequence from the source drop-down menu.

    • Select Add separate assessment block.

    • Select Open harness after creation.

  4. Click OK. The test harness for the shift_controller subsystem opens.

  5. Double-click the Test Sequence block. The Test Sequence Editor opens.

    Test Sequence editor with default step

  6. Create the test sequence.

    1. Rename the first step Accelerate and add the step actions:

      speed = 10*ramp(et);
      throttle = 100;
    2. Right-click the Accelerate step and select Add step after. Rename this step Stop, and add the step actions:

      throttle = 0;
      speed = 0;
    3. Enter the transition condition for the Accelerate step. In this example, Accelerate transitions to Stop when the system is in fourth gear for 2 seconds. In the Transition column, enter:

      duration(gear == 4) >= Limit

      In the Next Step column, select Stop.

    4. Add a constant to define Limit. In the Symbols pane, hover over Constant and click the add data button. Enter Limit for the constant name.

    5. Hover over Limit and click the edit button. In the Constant value field, enter 2. Click OK.

    Test Sequence editor with defined steps, transition, and next step

Create Basic Test Assessments

  1. Continuing the example, in the test harness, double-click the Test Assessment block to open the editor. The editor displays a When decomposition sequence.

  2. Rename the first step Assessments.

  3. Add two steps to Assessments. Right-click the Assessments step and select Add sub-step. Do this a second time. There should be four steps under Assessments.

  4. Enter the names and actions for the four substeps.

    Check1st when gear == 1
    verify(speed < 45)
    Check2nd when gear == 2
    verify(speed < 75)
    Check3rd when gear == 3
    verify(speed < 105)
    Else

    Test Sequence editor with assessments and verify statements

    The fourth step Else has no actions. Else handles simulation conditions outside of the preceding when conditions.

  5. Add a scope to the harness and connect the speed, throttle, and gear signals to the scope.

    Test harness with Test Sequence and Test Assessment blocks

  6. Set the model simulation time to 15 seconds and simulate the test harness. View the signal data by opening the scope.

    Signal data plots

  7. View the results of the verify statements in the Simulation Data Inspector.

    Plots of verify statements results

See Also

Related Topics