State Transition Testing
Model a system as a finite set of states and the events that move it between them. Test every valid transition — and verify that invalid transitions are rejected.
What it is
Many systems can only be in one state at a time, and move between states in response to events. A bank account is either Open, Frozen, or Closed. A booking is Pending, Confirmed, Cancelled, or Completed. State transition testing ensures all these paths work correctly.
The model has four elements:
- States — the distinct conditions the system can be in.
- Events (triggers) — inputs or actions that cause a transition.
- Transitions — the move from one state to another.
- Actions — what the system does when a transition occurs.
Building the state model
Start with a state diagram (boxes = states, arrows = transitions labelled with event/action). Then convert it to a transition table for easier test case derivation.
Worked example
Online order lifecycle: an order starts as Pending, can be Confirmed, Dispatched, Delivered, or Cancelled.
| Current State | Event | Next State | Action |
|---|---|---|---|
| Pending | Payment received | Confirmed | Send confirmation email |
| Pending | Customer cancels | Cancelled | Send cancellation notice |
| Confirmed | Stock allocated & shipped | Dispatched | Send tracking number |
| Confirmed | Customer cancels | Cancelled | Initiate refund |
| Dispatched | Delivery confirmed | Delivered | Close order, request review |
| Delivered | Customer cancels | Invalid | Error: cannot cancel delivered order |
| Cancelled | Payment received | Invalid | Error: order is cancelled |
Coverage criteria
There are three main coverage levels:
- 0-switch (all states) — visit every state at least once. Weakest.
- 1-switch (all transitions) — exercise every valid transition at least once. ISTQB Foundation standard.
- 2-switch (all transition pairs) — every consecutive pair of transitions. Strong but expensive.
Testing invalid transitions
A complete test suite also tests transitions that should not be possible. Try to cancel a delivered order. Try to dispatch a cancelled order. These tests verify the system rejects invalid state changes gracefully — not silently, and not by corrupting data.
Real-world value: state transition bugs are nasty to find manually. A user who somehow gets an order into an impossible state can create support nightmares. Model it formally and test the invalid paths explicitly.
ISTQB mapping
| Ref | Topic | Level |
|---|---|---|
| 4.2.4 | State Transition Testing | CTFL Foundation |
| FL-4.2.4 K3 | Apply state transition testing to derive test cases | Foundation LO |
| FL-4.2.4 K3 | Achieve specified coverage levels | Foundation LO |
Practice this technique: Try Junior Practice 10 — Multi-step form flow, Junior Practice 04 — NZ checkout form, Senior Practice 04 — Session & auth edge cases.
NZ example — RealMe identity verification
RealMe is New Zealand’s government identity verification service (used by IRD, NZTA, MSD). A RealMe account moves through states during verification.
| Current State | Event | Next State | Notes |
|---|---|---|---|
| Unverified | Submit documents | Pending | Documents under review |
| Pending | Documents accepted | Verified | Identity confirmed |
| Pending | Documents rejected | Unverified | Resubmit required |
| Verified | Fraud flag raised | Suspended | Suspicious activity detected |
| Suspended | Fraud cleared | Verified | Account reinstated |
| Verified | Closure requested | Closed | Account closure |
| Unverified | Jump to Verified | Invalid | No documents submitted — must be impossible |
| Suspended | Self-close account | Invalid | Admin-only action; user cannot self-close while suspended |
All-transitions coverage requires a test case for each valid transition. The two invalid transitions must also be tested — verify the system rejects them gracefully, not silently.
NZ library book loan system — state transition table
A library book can be in one of four states: Available, On Loan, Reserved, or Overdue. There are exactly 6 valid transitions. For each row, select the From state and To state, and type the triggering event.
| # | From state | Event (what triggers the change?) | To state |
|---|
| # | From state | Event | To state |
|---|---|---|---|
| 1 | Available | Member borrows book | On Loan |
| 2 | On Loan | Member returns book | Available |
| 3 | Overdue | Member returns book | Available |
| 4 | On Loan | Due date passes / book not returned | Overdue |
| 5 | Available | Member reserves book | Reserved |
| 6 | Reserved | Member borrows / reservation fulfilled | On Loan |