Log in
← Blog

State Transition Testing: Orders, Logins and Subscriptions

Cancelling a shipped order, logging in to a locked account: bugs that only happen in the wrong state. How to model states and test every move, including the refused ones.

Vihari Panyam

June 18, 2026 · 4 min read

A code editor stopped at a breakpoint, with the debugger showing the current values of each variable

In short

  • State transition testing models a feature as states (Placed, Paid, Shipped) and the events that move it between them.
  • Tests cover every valid transition, and just as important, the invalid ones the system must refuse.
  • It fits anything with a lifecycle: orders, accounts, subscriptions, tickets, payments and approvals.
On this page

A customer cancels an order. The refund goes out. An hour later the parcel arrives at their door, because the order had already shipped when they pressed Cancel and nothing stopped the button from working. Every individual feature passed its tests: cancelling works, shipping works, refunds work. Nobody tested cancelling a shipped order, because nobody drew the picture.

State transition testing is drawing that picture and testing every arrow in it, including the arrows that shouldn’t exist.

01States, events and transitions

  • State: a condition the thing can be in. An order can be Placed, Paid, Shipped, Delivered or Cancelled.
  • Event: something that happens. Payment received, Cancel pressed, Courier scans parcel.
  • Transition: an event moving the thing from one state to another. Paid + Ship = Shipped.
  • Guard: a condition on a transition. Cancel is allowed only if the order hasn’t shipped.

02Model the order lifecycle

FromEventTo
PlacedPayment succeedsPaid
PlacedPayment fails 3 timesCancelled
PlacedCustomer cancelsCancelled
PaidWarehouse shipsShipped
PaidCustomer cancelsCancelled (refund issued)
ShippedCourier deliversDelivered
DeliveredCustomer starts returnReturn requested
Valid transitions for an online order

Five states and seven arrows. Drawing them as boxes and arrows takes two minutes and is usually the most useful thing you will do all day, because the product owner will look at it and say "wait, Shipped orders can be cancelled if the courier hasn’t collected them yet." Now you know about a state nobody wrote down.

03The state table: where the invalid moves show up

A diagram shows what is allowed. A state table shows everything: every state against every event. The empty cells are the interesting ones, because each one is a move the system must refuse.

State \ EventPayCancelShipDeliver
PlacedPaidCancelledRefuseRefuse
PaidRefuse (no double charge)Cancelled + refundShippedRefuse
ShippedRefuseRefuse (start a return)RefuseDelivered
CancelledRefuseRefuseRefuseRefuse
DeliveredRefuseRefuseRefuseRefuse

04Turning the model into tests

  1. Every valid transition once. Seven tests for the order table. This is called 0-switch or single-transition coverage.
  2. Every invalid transition once. Each "Refuse" cell: try it, and check the system refuses with a clear message and the state doesn’t change.
  3. Common paths end to end. Placed → Paid → Shipped → Delivered, and Placed → Paid → Cancelled.
  4. Pairs of transitions for risky areas (1-switch coverage): every two-step sequence, such as Paid → Cancelled → Pay again.
test('a shipped order cannot be cancelled', async ({ request }) => {
  const order = await createOrder(request, { state: 'shipped' });
  const res = await request.post(`/api/orders/${order.id}/cancel`);
  expect(res.status()).toBe(409);                       // conflict, not success
  expect((await getOrder(request, order.id)).state).toBe('shipped');
  expect(await refundsFor(request, order.id)).toHaveLength(0);
});
typescript

05Two more models worth drawing

Login and lockout

States: Active, Failed once, Failed twice, Locked, Locked until reset. Test that the third wrong password locks the account, that the correct password is refused while locked, and that the counter resets after a successful login. A surprising number of systems forget the last one, so two wrong passwords a day eventually lock out a careful user.

Subscriptions

States: Trial, Active, Past due, Paused, Cancelled. The tricky events are the ones driven by time and by the payment provider: the trial ending at midnight in the customer’s time zone, a card failing on renewal, a payment succeeding after the account was already marked past due.

06Events that come from outside

Many transitions are triggered by things you don’t control: payment webhooks, courier updates, timers. They can arrive late, twice, or out of order. For each external event, add three tests: the event arriving twice, arriving for an order already in a later state, and arriving after the order was cancelled.

State transition checklist

  • States and events are drawn and agreed with the product owner
  • A state table lists every state against every event
  • Every valid transition has a test
  • Every invalid transition has a test that checks it is refused and nothing changed
  • Main paths are tested end to end
  • External events are tested arriving twice, late and out of order

Frequently asked questions

What is state transition testing?

A test design technique that models a system as states and the events that move it between them, then tests the valid transitions and checks that invalid ones are refused.

What is the difference between a state diagram and a state table?

A diagram shows the allowed transitions as arrows. A table lists every state against every event, which makes the invalid combinations visible so they can be tested too.

What is 0-switch and 1-switch coverage?

0-switch coverage tests every single transition once. 1-switch coverage tests every pair of consecutive transitions, which catches bugs that depend on what happened just before.

When should I use state transition testing?

Whenever something has a lifecycle and behaves differently depending on its current state: orders, accounts, logins, subscriptions, tickets, approvals and payments.

How do I test invalid transitions?

Put the system in a state, trigger an event that shouldn’t be allowed there, and check three things: it is refused with a clear message, the state didn’t change, and no side effects (like refunds or emails) happened.

Written by

Vihari Panyam

QualityAIQ

Sources and further reading

  1. ISTQB Certified Tester Foundation Level: state transition testing
  2. ISTQB Glossary: state transition testing
  3. MDN: HTTP 409 Conflict and other status codes

More in Test Design