Modules
Advanced⏱ 7 min read

State Transition Testing

sign in to track

State Transition Testing is a test design technique used to verify how a system behaves when it moves from one state to another based on an event or condition.

It is especially useful for stateful systems, where the system's current behavior depends on what happened previously.

In simple terms:

Current State + Event/Condition → Next State + Expected Behavior

For example, an account may move from Active to Locked after several failed login attempts.

Key Concepts

1. State

A state represents the current condition or status of the system.

Examples:

  • Active

  • Inactive

  • Locked

  • Pending

  • Approved

  • Rejected

  • Paid

  • Cancelled

2. Transition

A transition is the movement from one state to another caused by an event or action.

Example:

Active → Locked

The transition may happen when the user enters an incorrect password too many times.

3. Event

An event is an action or occurrence that causes a transition.

Examples:

  • User logs in.

  • Payment is completed.

  • Order is cancelled.

  • Password is entered incorrectly.

  • Approval is submitted.

4. Guard or Condition

A guard is a condition that must be satisfied for a transition to occur.

Example:

Active → Locked

Event: Failed login attempt
Condition: Failed attempts ≥ 5

The account should only become locked when the required condition is met.

Example: Account Locking

Suppose an application locks an account after three consecutive failed login attempts.

Possible states:

  • Active

  • Locked

Possible behavior:

  • Successful login → Remains Active

  • First failed attempt → Remains Active

  • Second failed attempt → Remains Active

  • Third failed attempt → Changes to Locked

  • Login attempt while Locked → Access denied

The important point is that the system's response depends on its current state and previous events.

Step-by-Step Testing

1. Identify the States

Determine the different states the system can have.

Example:

Active → Locked

2. Identify Events

Determine what actions can cause state changes.

Examples:

  • Successful login

  • Failed login

  • Account unlock

3. Identify Conditions

Determine whether any conditions control the transition.

Example:

  • Account becomes locked after 3 consecutive failed attempts.

4. Identify Valid Transitions

Determine which state changes should be allowed.

Example:

Active → Locked

5. Identify Invalid Transitions

Check what happens when an action is attempted from a state where it should not be allowed.

Example:

  • A locked user attempts to log in.

  • A cancelled order attempts to be shipped.

  • A rejected application attempts to move directly to approved.

6. Create Test Cases

Convert the identified transitions into test cases and verify the expected state and behavior.

Real-World Example: Order Status

An e-commerce order may have states such as:

Pending → Confirmed → Shipped → Delivered

Other possible transitions may include:

Pending → Cancelled

Testers should verify that:

  • A pending order can be confirmed.

  • A confirmed order can be shipped.

  • A shipped order can be delivered.

  • A pending order can be cancelled.

  • A delivered order cannot be cancelled.

  • A cancelled order cannot be shipped.

  • Invalid state transitions are rejected appropriately.

Valid vs Invalid Transitions

Valid Transition

A transition that the system allows according to its requirements.

Example:

Pending → Confirmed

when the order is successfully confirmed.

Invalid Transition

A transition that should not be allowed.

Example:

Delivered → Shipped

A delivered order should not normally move back to the shipped state.

Testing invalid transitions is important because systems may behave incorrectly when users perform actions in an unexpected order.

When to Use State Transition Testing

This technique is useful when:

  • The system has clearly defined states.

  • Previous actions affect current behavior.

  • Different actions produce different states.

  • The order of user actions matters.

  • The system has workflows or status-based rules.

Common examples include:

  • User account locking

  • Order management

  • Payment processing

  • Subscription lifecycle

  • Ticket/issue management

  • Approval workflows

  • Login/session management

  • Booking systems

  • Device states

Advantages

  • Helps verify complete workflows.

  • Tests both valid and invalid state changes.

  • Finds defects caused by incorrect event sequences.

  • Useful for systems where history affects behavior.

  • Helps identify missing or unexpected transitions.

  • Makes complex workflows easier to understand.

◈Key Points

  • Identify all valid states, all possible events, all valid transitions, and all invalid transitions.
  • Draw a state diagram — visual representation catches missing transitions that text descriptions miss.
  • Testing strategies: 0-switch (test every valid transition once), 1-switch (test every pair of sequential transitions).
  • Invalid transition testing: attempt transitions that should be blocked and verify rejection.
  • Key use cases: order management systems, user authentication flows, booking/reservation engines.
⚡ Expert Pro Tip

State diagrams are one of the best communication tools between QA and developers. Building one together at the start of a feature often exposes unspecified states before a line of code is written.