← Back to libraryQuestion 312 of 468

State Transition Testing

📌 Definition:

State Transition Testing is a black-box technique for systems whose behavior depends on their current STATE and the events that move between states. You model states, transitions, events, and actions, then design tests for valid and invalid transitions.

📖 Detailed Explanation:

You draw a state transition diagram (or table): states (e.g. Logged Out, Logged In, Locked), events (login, wrong password x3, logout), and the resulting transitions/actions. Tests cover valid transitions (login → Logged In), invalid ones (can you jump states illegally?), and sequences (3 wrong passwords → Locked). It's ideal for workflows, account lifecycles, order status, and any system with modes. It catches bugs where the system allows an illegal transition or mishandles an event in a given state. A powerful technique for stateful features and a strong senior-level answer.

🔑 Key Points:
  • Models states + events + transitions + actions
  • Test valid AND invalid transitions and event sequences
  • Ideal for lifecycles/workflows (login lockout, order status)
  • Catches illegal transitions and state-specific event bugs
🌍 Real-World Example:

An account lockout: Active → (3 failed logins) → Locked → (admin unlock) → Active. Tests verify the lock happens exactly at the 3rd failure and that a locked account rejects even correct credentials until unlocked.

🎯 Scenario-Based Interview Question:

A user account locks after 3 failed logins and unlocks only via admin. What technique tests this and what transitions do you check?