State Transition Testing
What is State Transition Testing?
State transition testing is a black box technique used for systems whose behaviour depends on their current state and historical inputs, verifying that the system moves correctly between different states.
Key Concepts
- States: Distinct conditions the system can be in (e.g., "Logged Out," "Logged In," "Locked").
- Transitions: The valid changes from one state to another, triggered by specific events.
- Events: Actions or inputs that cause a state transition (e.g., entering a correct/incorrect password).
Test Design Using State Diagrams
Testers use state diagrams or state tables to visualise all valid states and transitions, then derive test cases that cover valid transitions, invalid transitions, and sequences of transitions (e.g., testing an account lockout after multiple failed login attempts).
Worked Example: Login With Account Lockout
Take a rule many apps follow: three wrong passwords in a row lock the account until an administrator unlocks it. The states are:
- S0 Logged out, no failed attempts
- S1 Logged out, one failed attempt
- S2 Logged out, two failed attempts
- S3 Locked
- S4 Logged in
The state table
A state table lists every state against every event. Empty or "no change" cells are where invalid transitions hide, and they are just as important to test.
| Current state | Correct password | Wrong password | Logout | Admin unlock |
|---|---|---|---|---|
| S0 | S4 | S1 | Not allowed | No change |
| S1 | S4 | S2 | Not allowed | No change |
| S2 | S4 | S3 | Not allowed | No change |
| S3 | Stays S3, locked message | Stays S3 | Not allowed | S0 |
| S4 | Not applicable | Not applicable | S0 | No change |
Deriving Test Cases From the Table
| ID | Start | Events | Expected end state and check |
|---|---|---|---|
| TC1 | S0 | Correct password | S4, dashboard opens |
| TC2 | S0 | Wrong, wrong, wrong | S3, lockout message shown |
| TC3 | S2 | Correct password, logout, wrong password | S1, counter was reset by the successful login |
| TC4 | S3 | Correct password | Still S3, login refused |
| TC5 | S3 | Admin unlock, correct password | S4 |
| TC6 | S0 | Direct call to logout endpoint | Request rejected, still S0 |
TC3 is the kind of case that finds real bugs. Many systems forget to reset the failure counter after a successful login, so a user who mistypes twice on Monday and once on Friday gets locked out unfairly.
How Much Coverage Is Enough?
- All states: every state is visited at least once. This is the weakest level.
- All valid transitions (0-switch): every arrow in the diagram is exercised once. This is the usual minimum for a formal test design.
- Pairs of transitions (1-switch): every sequence of two consecutive transitions is tested, which catches bugs that depend on history, like the counter reset above.
- Invalid transitions: each "not allowed" cell is attempted to prove the system refuses it.
The technique fits anything with a lifecycle: order statuses from placed to delivered, ticket workflows in tools such as Jira, ATM sessions, traffic signals, and subscription plans moving between trial, active, paused and cancelled.
Mistakes When Applying the Technique
- Testing only the happy path through the diagram and skipping invalid events.
- Ignoring guard conditions, such as "only if the balance is enough", which split one transition into two outcomes.
- Forgetting time-based events, like a lock that releases automatically after a waiting period or a session that expires.
- Drawing the diagram from the code rather than the requirement, which copies the developer's mistakes into the tests.
Practical routine: draw the diagram, convert it to a table, fill every empty cell with an expected response, then write one test per valid transition and one per important invalid one.
Ready to master real-world software testing?
Learn manual and automation testing hands-on with mentor-led sessions.