What is state transition testing?
Some features always react the same way: a calculator adds 2 + 2 the same way every time. Many others remember where they are, and the same action gives a different result depending on that. Tapping Cancel on a fresh order should cancel it. Tapping it on a delivered order should not.
State transition testing is a black-boxBlack-box testingTesting based only on inputs and outputs, without looking at the code.Open in glossary → test design technique for those features. You draw the places the system can be in (its states), the things that move it between them (events), and then you test both the moves that should happen and the ones that should not.
The building blocks
| Word | Meaning | Example |
|---|---|---|
| State | A situation the system is in, which changes how it reacts | Stopped, Playing, Paused |
| Event | Something that happens: a tap, a timer, a server message | The user taps Pause |
| Transition | A move from one state to another, caused by an event | Playing → Paused |
| Guard | A condition that must be true for the transition to happen | Refund only if delivered ≤ 30 days ago |
| Action | What the system does while it moves | Remember the playback position |
Here is the music player drawn as a state diagram. Boxes are states, arrows are transitions, and the label on each arrow is the event. The small dot with an arrow marks the initial state (where everything starts).
Notice what is not on the diagram: there’s no arrow for “Pause while Stopped” or “Play while Playing”. Those are invalid transitions, and they are where a lot of bugs hide. Pressing Play twice in a row in a buggy player can start the same song twice, on top of itself.
The building blocks in depth
States
A state is a situation that changes how the system reacts to the same input. That definition is the test for whether something deserves to be a state.
- “The order is paid” is a state, because Pay, Cancel and Refund all behave differently once it’s true.
- “The order has a blue shipping label” is not a state if nothing behaves differently because of it.
Two special kinds of state appear in almost every model:
- The initial state is where the system starts: a new order is Placed, a fresh login screen has 0 wrong attempts. On a diagram it’s marked with a small filled dot and an arrow.
- A final state is one the system never leaves: a Canceled or Refunded order. It’s drawn with a double border. Final states are great places to test, because every event there should be rejected.
Events and transitions
An event is anything that can happen to the system. Some come from the user (tap Cancel), some from time (15 minutes pass, the paid parking time runs out), and some from other systems (the courier’s scanner says “delivered”, the bank confirms a payment, a push notificationPush notificationA message an app sends to the device that appears even when the app is closed.Open in glossary → arrives).
A transition is the arrow: in state A, when event E happens, go to state B. A transition can also go back into the same state. A bank card that is Active stays Active after a successful payment, but something still happens: money moves. That’s called a self-transition.
Guards
A guard is a yes/no condition written in square brackets on an arrow, like refund [≤ 30 days since delivery]. The same event in the same state can go different ways depending on the guard:
- Delivered + Refund [within 30 days] → Refunded
- Delivered + Refund [after 30 days] → stays Delivered, with the message “The return window has closed”
Guards are where state transition testing meets boundary value analysisBoundary value analysisTesting values at and just around the edges of valid ranges, where bugs love to hide.Open in glossary →: test day 30 and day 31, not just day 5. And where several conditions combine (amount, country, membership level), a decision tableDecision tableA table listing combinations of conditions and the action the software should take for each.Open in glossary → is the better tool for the guard itself. See boundary value analysis and decision tables.
Actions
An action is what the system does during a transition: charge the card, send the tracking email, reset the counter, release the reserved stock. Written after a slash: cancel / refund payment.
Actions matter because a transition can land in the right state and still do the wrong thing. If canceling a paid order shows “Canceled” but never refunds the money, the state is correct and the customer is still out $84. Always check the state and the action in your expected resultExpected resultWhat should happen when you perform a test step, according to the requirements.Open in glossary →.
Check this part
In a music player, the user taps Pause while it's Playing and it moves to Paused. What is "tap Pause" in state transition terms?
The music player diagram has no arrow for "Pause while Stopped". What is that combination?