Ir al contenido principal
Beginner reading +15 XP

State Transition Testing

Some software behaves differently depending on what happened before. The same button click might do different things depending on the current state of the system. When behavior depends on history, you need state transition testing.

What's a State?

A state is a condition the system is in at a given moment. An order can be: Draft → Submitted → Processing → Shipped → Delivered → Returned. A user account can be: Active → Suspended → Closed.

A transition is the event that moves the system from one state to another. "Customer clicks Submit" transitions an order from Draft to Submitted. "Admin clicks Suspend" transitions an account from Active to Suspended.

The State Transition Diagram

Let's model a simple ATM PIN entry:

[Start] --enter PIN--> [PIN Entered]
[PIN Entered] --correct--> [Access Granted]
[PIN Entered] --wrong (attempt 1)--> [1st Failure]
[1st Failure] --correct--> [Access Granted]
[1st Failure] --wrong (attempt 2)--> [2nd Failure]
[2nd Failure] --correct--> [Access Granted]
[2nd Failure] --wrong (attempt 3)--> [Card Blocked]

Deriving Test Cases

From the diagram, you derive test paths:

  1. Happy path: Enter correct PIN → Access granted (1 transition)
  2. One wrong attempt: Wrong → Correct → Access granted (2 transitions)
  3. Two wrong attempts: Wrong → Wrong → Correct → Access granted (3 transitions)
  4. Card blocked: Wrong → Wrong → Wrong → Blocked (3 transitions)
  5. Invalid transition: Try to access without entering PIN (should be impossible)

Test case #5 is important — you're testing that invalid transitions are blocked. Can a user reach "Access Granted" without going through "PIN Entered"? In a web application, could they manipulate the URL or API to skip a step?

When to Use This

State transition testing is essential for:
- Workflows (order processing, approval chains, ticket lifecycles)
- Authentication (login attempts, session states, account lockout)
- Navigation (wizard steps, multi-page forms)
- Connection handling (connected, disconnected, reconnecting)

The Key Question

For every state, ask: "What happens if I try something unexpected here?" What if I click Back on the payment confirmation page? What if I submit an already-submitted order? What if my session expires mid-checkout?

The bugs that matter most are the ones at unexpected transitions.

The key takeaway: Draw the states. Draw the arrows. Then test the arrows that shouldn't exist — that's where the bugs are.

Exercise Multiple Choice

In the ATM PIN example, a user enters the wrong PIN twice, then enters the correct PIN. What should happen?

Exercise Put in Order

Put these order states in the correct lifecycle sequence.

Delivered
Shipped
Submitted
Processing
Draft
Exercise Flashcard

What are "invalid transitions" in state transition testing, and why are they important to test?

Click to reveal answer