QA Interview Hub · Knowledge base · Quizzes · Українська

QA Fundamentals › Test design techniques

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

New Paid Shipped Delivered pay ship deliver Cancelled cancel cancel only from New and Paid
Figure 1. The diagram shows only the allowed transitions. Everything missing from it must be checked as forbidden.

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

StateAllowedForbidden
Newpay → Paid; cancel → Cancelledship, deliver
Paidship → Shipped; cancel → Cancelledpay, deliver
Shippeddeliver → Deliveredpay, ship, cancel
Delivered—pay, ship, deliver, cancel
Cancelled—pay, ship, deliver, cancel
Figure 2. Five valid transitions and fifteen forbidden "state + event" pairs: every forbidden pair is a negative test.

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.

In an interview. Junior: For entities with states, such as a payment or an order, I draw a state diagram and check all valid transitions. And most importantly the invalid ones: a delivered order cannot be cancelled, and a refunded payment cannot be refunded again. Middle/Senior: I build a state table to see the forbidden pairs and pick the risky ones. I check forbidden transitions through the API, because the interface does not prove protection on the server, and I look at side effects: money, emails, events. Separately I test races of two events.

More articles in this chapter