State transition testing coverage criteria for ISTQB CTFL
ISTQB's CTFL v4.0 syllabus covers three criteria. All states coverage exercises every state. Valid transitions coverage, also called 0-switch coverage, exercises every valid transition. All transitions coverage exercises every valid transition and attempts every invalid one. Full all transitions coverage guarantees the other two, and reaching full valid transitions coverage also means every state has been exercised.
State diagram vs state table
A state diagram models behaviour by showing the possible states and the valid transitions between them. An event starts a transition, and a guard condition can qualify it. Transitions are treated as instantaneous and may result in the software taking an action. The usual label is event [guard condition] / action. The guard and the action can be left out when they do not exist or do not matter to the tester.
A state table is an equivalent model. Its rows are states and its columns are events, together with guard conditions if there are any. Each cell is a transition and holds the target state and any resulting actions.
The difference that matters for testing: a state table shows invalid transitions explicitly, as empty cells. A state diagram shows only the valid ones.
How are the three coverage criteria measured?
All states coverage is the states exercised divided by all states. Valid transitions coverage is the valid transitions exercised divided by all valid transitions. All transitions coverage counts both kinds: transitions exercised (valid) or attempted (invalid), divided by every transition in the state table.
Example: a model has 4 states and 3 events, so its state table has 12 cells. 6 cells are filled, which means 6 valid and 6 invalid transitions. A suite that exercises all 6 valid transitions and attempts 3 invalid ones reaches 100% valid transitions coverage, 100% all states coverage, and 9 / 12 = 75% all transitions coverage.
All states coverage is the weakest of the three, because it can usually be reached without exercising every transition. Valid transitions coverage is the one used most often. The syllabus treats all transitions coverage as the minimum for mission-critical and safety-critical software.
What does a state transition test case look like?
A test case is usually a sequence of events. The events drive the system through a series of state changes, with actions where they are defined. One test case may cover several transitions, and usually does.
For invalid transitions, the syllabus recommends testing only one per test case. This helps avoid defect masking, where one defect prevents another from being detected.
Where the exam catches people
Believing a state diagram shows invalid transitions: only the state table shows them, as empty cells.
Reading empty cells in a state table as unfinished specification: they represent invalid transitions.
Dividing by the number of valid transitions when calculating all transitions coverage: the denominator is every cell, valid and invalid.
Believing 100% all states coverage means every transition was exercised: it is weaker than valid transitions coverage.
Writing a separate test case for every single transition: one test case normally covers several transitions. Only invalid transitions are best tested one per test case.