What is state transition testing?
State transition testing checks how an object moves between states through events, including transitions that should not exist. The model has states, events, transitions and actions, and coverage grows from all states to all valid transitions and all transitions, including invalid ones. Forbidden state and event pairs become negative tests, and side effects and server-side protection are checked apart from the UI.
QA Fundamentals · Test design techniques
The order is already delivered. What happens if the customer presses "Cancel"?
A tester walked the order path from creation to delivery, and everything worked. But what happens if, after delivery, a cancel request is sent straight to the API, or "Pay" is clicked twice? For entities that pass through states (an order, a payment, an account, a ticket), errors most often hide not in the states themselves but in the transitions between them, especially those that should not exist. This is the area of state transition testing.
How it works and why
The model has four parts: a state (where the object is now), an event (what happened: payment, shipment), a transition (state → event → new state) and an action (a side effect: an email, a debit). Sometimes a transition also has a guard: cancelling is allowed if the order has not been shipped yet.
Order states and allowed transitions
ISTQB defines three growing levels of coverage: all states (every state visited), all valid transitions (every arrow walked) and all transitions, including invalid ones. The last level is the most expensive, but it is the one that finds errors not visible on the diagram.
Example: the state table
Invalid transitions are not drawn on the diagram, so they are found from a state table: for each state it shows the allowed events and the forbidden ones, and every forbidden "state + event" pair (an empty cell in the classic "state × event" grid) becomes a negative test.
State table: what is allowed in each state
| State | Allowed | Forbidden |
|---|---|---|
| New | pay → Paid; cancel → Cancelled | ship, deliver |
| Paid | ship → Shipped; cancel → Cancelled | pay, deliver |
| Shipped | deliver → Delivered | pay, ship, cancel |
| Delivered | — | pay, ship, deliver, cancel |
| Cancelled | — | pay, ship, deliver, cancel |
The valid transitions are covered by three tests: New → Paid → Shipped → Delivered, New → Cancelled and New → Paid → Cancelled. For each, check not only the new state but also the side effect: after cancelling a paid order a refund must start.
Of the fifteen forbidden pairs, the risky ones are chosen: Delivered + cancel, Cancelled + pay (paying a cancelled order), Paid + pay (a double click), New + ship (skipping payment), Shipped + cancel. The expected result is the same: an error with a proper code or message, while the state and the money stay unchanged. Payments work the same way: Declined → Captured is not allowed, and Refunded → Refunded must not return the money a second time.
A forbidden transition is checked not only through the interface. The "Cancel" button may be hidden in the Delivered state, but the server must reject such a request itself, because a request can be sent directly, replayed from a stale tab or race with another event.
Limits and alternatives
- The model is useful while the states are few. If there are dozens, the diagram is split into sub-machines or risky paths are chosen.
- When behaviour depends on history ("there was already one failed payment"), that is an extra state or a counter, not a new technique.
- Simultaneous events (two tabs, a repeated request) are not shown on the diagram. They are checked separately as races.
- For a result that depends on a combination of conditions within one state, a decision table is used alongside.
Typical mistakes
- Checking only the happy path. It does not even reach valid transitions coverage: both cancellations stay untested, let alone the forbidden transitions.
- Looking only at the interface. A hidden button does not prove the server forbids the transition.
- Not checking side effects. The state changed, but the email, the refund or the analytics event did not happen.
- Mixing a state and an attribute. "Paid" is a state, while "order amount" is not.
Check yourself
A model has 5 states and 4 events, with 5 valid transitions. How many forbidden "state + event" pairs are there?
Answer
5 × 4 = 20 pairs, of which 5 are valid, so 15 are forbidden. Each can be covered by a negative test, but in practice the risky ones are chosen.
Why check a forbidden transition at the API level if the interface has no button?
Answer
Because a request can be sent directly, replayed from an old tab or arrive in a race with another event. Protection only in the interface does not prove that the server keeps the state and the money consistent.
How does "all valid transitions" coverage differ from "all transitions"?
Answer
The first walks every arrow of the diagram. The second additionally tries every forbidden combination of state and event and checks that the system rejects it without side effects.