Course outline
State transition tool
Write how something moves from state to state; it draws the state table, finds the invalid moves and writes the cases.
Some features behave differently depending on what happened before: an order that is paid cannot be paid again, a checkout waiting for the bank should not accept a second card. State transition testing describes those states and the events that move between them, then tests every move, and the moves that must not happen.
Write each move as "From > event > To". The tool draws the state table (every state against every event), lists the invalid moves the table reveals, and writes test cases for every move (0-switch) or every two moves in a row (1-switch).
Use the tool
One move per line, written "From > event > To".
4 states, 6 events, 6 moves; 18 invalid moves (the dashes).
| State | go to checkout | back to the basket | pay, card approved | pay, card declined | pay, bank slow | bank approves |
|---|---|---|---|---|---|---|
| Basket | Checkout | — | — | — | — | — |
| Checkout | — | Basket | Confirmed | Checkout | Waiting for the bank | — |
| Confirmed | — | — | — | — | — | — |
| Waiting for the bank | — | — | — | — | — | Confirmed |
| Case | Start in | Do | Expect |
|---|---|---|---|
| 1 | Basket | go to checkout | Checkout |
| 2 | Checkout | back to the basket | Basket |
| 3 | Checkout | pay, card approved | Confirmed |
| 4 | Checkout | pay, card declined | Checkout |
| 5 | Checkout | pay, bank slow | Waiting for the bank |
| 6 | Waiting for the bank | bank approves | Confirmed |
The 18 invalid moves
- In "Basket", try "back to the basket": it must be refused or ignored.
- In "Basket", try "pay, card approved": it must be refused or ignored.
- In "Basket", try "pay, card declined": it must be refused or ignored.
- In "Basket", try "pay, bank slow": it must be refused or ignored.
- In "Basket", try "bank approves": it must be refused or ignored.
- In "Checkout", try "go to checkout": it must be refused or ignored.
- In "Checkout", try "bank approves": it must be refused or ignored.
- In "Confirmed", try "go to checkout": it must be refused or ignored.
- In "Confirmed", try "back to the basket": it must be refused or ignored.
- In "Confirmed", try "pay, card approved": it must be refused or ignored.
- In "Confirmed", try "pay, card declined": it must be refused or ignored.
- In "Confirmed", try "pay, bank slow": it must be refused or ignored.
- In "Confirmed", try "bank approves": it must be refused or ignored.
- In "Waiting for the bank", try "go to checkout": it must be refused or ignored.
- In "Waiting for the bank", try "back to the basket": it must be refused or ignored.
- In "Waiting for the bank", try "pay, card approved": it must be refused or ignored.
- In "Waiting for the bank", try "pay, card declined": it must be refused or ignored.
- In "Waiting for the bank", try "pay, bank slow": it must be refused or ignored.
How the method works
The state table has a row for each state and a column for each event. A cell holds the state the event leads to; an empty cell is an invalid move: the system should refuse it, or ignore it safely. Those empty cells are where unexpected behaviour hides, so test some of them too.
0-switch coverage takes each valid move once. 1-switch coverage takes each pair of moves that can follow one another (pay with a slow bank, then the bank approves), which finds bugs that only appear after a certain path. Start each case in its first state; reach that state with the moves before it if you need to.
- One move per line: "From > event > To". States and events are taken from the moves.
- Check the state table: every empty cell is a move that must not happen. Ask about the ones nobody has decided.
- Run the 0-switch cases first, then the 1-switch cases for the paths that matter most.
A worked example on Cedar Books
An order at Cedar Books goes from the basket to checkout, and from there to confirmed, back to the basket, or to a wait for a slow bank (REQ-07). Six moves give this state table:
| State | go to checkout | back to the basket | pay, card approved | pay, card declined | pay, bank slow | bank approves |
|---|---|---|---|---|---|---|
| Basket | Checkout | — | — | — | — | — |
| Checkout | — | Basket | Confirmed | Checkout | Waiting for the bank | — |
| Confirmed | — | — | — | — | — | — |
| Waiting for the bank | — | — | — | — | — | Confirmed |
Four states and six events make 24 cells; 6 are moves, so 18 are invalid moves: paying again from Confirmed is one worth trying. The 1-switch cases add paths such as a declined card followed by an approved one.