TestPrepPro

State Transition Testing: A Complete Guide with Examples

state transition testing examplesstate transition diagramstate transition testing ISTQB

What Is State Transition Testing?

State transition testing is a black-box test design technique that models system behavior as a finite number of states and the transitions between them. It is particularly useful for testing systems where outputs depend not just on current inputs but also on the history of previous inputs — in other words, systems that have memory.

Understanding state transition testing with examples is essential for ISTQB Chapter 4, where this technique is tested at the K3 (application) level.

Key Concepts

A state transition model has four components:

States: The distinct conditions a system can be in (e.g., Locked, Unlocked, Blocked).

Transitions: The movement from one state to another, triggered by an event.

Events: The inputs or actions that cause transitions (e.g., "enter correct PIN").

Actions: The outputs or behaviors that occur during a transition (e.g., "display welcome screen").

State Transition Testing Example 1: ATM PIN Entry

Consider an ATM that allows three attempts to enter a correct PIN before blocking the card.

States: S1 (Card Inserted), S2 (First Attempt Failed), S3 (Second Attempt Failed), S4 (Access Granted), S5 (Card Blocked).

Transitions: - S1 + correct PIN = S4 (Access Granted) - S1 + wrong PIN = S2 (First Attempt Failed) - S2 + correct PIN = S4 (Access Granted) - S2 + wrong PIN = S3 (Second Attempt Failed) - S3 + correct PIN = S4 (Access Granted) - S3 + wrong PIN = S5 (Card Blocked)

From this model, you can derive test cases that cover every transition. A minimum set of state transition testing test cases would be:

Test 1: Insert card, enter correct PIN on first attempt. Expected: Access Granted. Test 2: Insert card, enter wrong PIN, then correct PIN. Expected: Access Granted. Test 3: Insert card, enter wrong PIN twice, then correct PIN. Expected: Access Granted. Test 4: Insert card, enter wrong PIN three times. Expected: Card Blocked.

State Transition Testing Example 2: Online Order Status

An e-commerce order moves through these states: Placed, Confirmed, Shipped, Delivered, Cancelled.

Valid transitions: - Placed to Confirmed (payment verified) - Placed to Cancelled (customer cancels or payment fails) - Confirmed to Shipped (warehouse dispatches) - Confirmed to Cancelled (customer cancels before shipping) - Shipped to Delivered (carrier confirms delivery)

Invalid transitions to test: - Shipped to Cancelled (should not be possible) - Delivered to any other state (final state) - Placed directly to Shipped (must be confirmed first)

Testing invalid transitions is just as important as testing valid ones. These state transition testing examples show that the technique catches both missing functionality and incorrect state changes.

State Transition Tables

A state transition table is a structured way to document all states, events, and resulting transitions. Each row represents a current state, each column represents an event, and each cell contains the next state.

For the ATM example:

| Current State | Correct PIN | Wrong PIN | |---|---|---| | Card Inserted | Access Granted | Attempt 1 Failed | | Attempt 1 Failed | Access Granted | Attempt 2 Failed | | Attempt 2 Failed | Access Granted | Card Blocked |

This table format makes it easy to identify all required test cases and ensures no transition is missed.

Coverage Levels

State transition testing defines different coverage levels:

- All states coverage: Every state is visited at least once - All transitions coverage (0-switch): Every valid transition is exercised at least once - All transition pairs (1-switch): Every pair of consecutive transitions is tested

For the ISTQB Foundation Level exam, you are expected to understand and apply all-transitions coverage.

Tips for the ISTQB Exam

When you encounter state transition testing questions on the exam, start by drawing the state diagram. Identify all states and transitions from the specification. Then systematically derive test cases to cover each transition. Count carefully — the exam often asks for the minimum number of test cases needed.

Practice this technique with our free ISTQB practice questions to build speed and accuracy before exam day.

Ready to Practice?

Try our free ISTQB practice questions with detailed explanations.

Start Free Practice