Module 4: State Transition Testing
An order cannot be shipped if it has been cancelled. A cancelled subscription cannot be renewed directly without reactivating. A sold item cannot be equipped without being repurchased. These constraints sound obvious in a meeting — and yet developers fail to enforce them all the time.
State transition testing is the discipline of making object life cycles explicit, testable, and provably complete.
Lessons in this module
- Objects Have a Life Cycle — Introduction to state machines: what states are, what transitions are, and why every non-trivial entity in a system has a state model worth testing. Build your mental model with real examples from e-commerce, task management, and user accounts.
- Valid vs. Invalid Transitions — The state table: a matrix of current states vs. events, mapping each cell to either a valid next state or a rejection. Learn to identify which invalid transitions are tested vs. which are just assumed to "never happen."
- Reading and Drawing State Diagrams — Learn the notation: circles for states, arrows for transitions, labels for events and guards. Practice reading existing diagrams and drawing your own from a written specification.
Practice: RPG Inventory Status
An item can be Equipped, Unequipped, or Sold. Some transitions are valid; two are bugs. Your job: find the forbidden path from Sold to Equipped — and any other invalid transition the backend failed to block.
By the end of this module, you will earn the State Machine Shepherd badge.