June 02, 2019

State Transition Testing Technique with Examples

State Transition Testing is a test design technique, which you can use to design test cases. Now, what is a state in state transition? A state is a particular condition in which the system under test can exist. A state A state has certain attributes or properties and it has a certain behavior. What is transition? A transition is movement from one valid (allowed) state to another valid state. These transitions are tested in state transition testing. View the detailed State Transition Testing tutorial or read on...

Light switch example State Diagram




Let us assume that a lighting system has a switch, an electric circuit and a light. As you can see in the state transition diagram above, there are only two valid states in which this system can exist - OFF and ON. In the OFF state, you can provide an input (turn switch on) to cause a transition to the ON state with the output that the light becomes on. In the ON state, you can provide an input (turn switch off) to cause a transition to OFF state with the output that the light becomes off. In state transition testing, you would test both these transitions i.e. OFF state to ON state and ON state to OFF state.

Car State Diagram example


Let us see another state transition example. The above diagram is also called the the State Graph or the State Chart or State Transition Chart or State Transition Graph. This diagram shows the four possible states of a car - Stopped, Accelerating, Constant Speed and Braking. From the Stopped state, the system can only change to the Accelerating state. From the Accelerating state, it is possible to change to the Constant Speed state and vice versa. From the Constant Speed state, it is possible to change the car to the Braking state and vice versa. From the Braking state, it is possible to change to the Accelerating state and vice versa. Also, from the Braking state, it is possible to change to the Stopped state. Therefore, there are 8 valid transitions (represented by 8 arrows) that you should test.

State Table and State Diagram are related. The same information is shown in the form of a state table or state transition table. The first 8 rows after the header are the valid transitions. The next 4 rows are the invalid transitions. You should also test the invalid transitions to ensure that they are impossible.

StateInputNext State
StoppedPress gas pedal Accelerating
AcceleratingKeep gas pedal constantConstant Speed
AcceleratingSwitch to brake pedalBraking
Constant SpeedPress gas pedal moreAccelerating
Constant SpeedSwitch to brake pedalBraking
BrakingSwitch to gas pedal; press gas pedal moreAccelerating
BrakingSwitch to gas pedalConstant Speed
BrakingKeep brakingStopped
Stopped?Constant Speed
Stopped?Braking
Accelerating?Stopped
Constant Speed?Stopped

You can design state transition testing test cases based on the state transition table. For example, you can write test cases based on the workflows as follows. Ensure that you cover each valid transition and each invalid transition.
Test case 1– Stopped | Accelerating | Constant Speed | Braking | Stopped
Test case 2– Stopped | Accelerating | Braking | Accelerating | Braking | Stopped
Test case 3 – Stopped | Accelerating | Constant Speed | Accelerating | Constant Speed | Braking | Constant Speed | Braking | Stopped
and so on.

I hope that you found the above state diagram examples useful.to understand state transition testing. If you want to learn more, you can view my State Transition Testing tutorial. I have explained the above concepts in greater detail in it.

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.