TDD a state machine

A state machine is a very specific way to organize the logic in your application. In this learning hour we practice building the state machine iteratively and incrementally with TDD.

Learning Objectives

Session Outline

Connect - tests for a state machine

We’re assuming the participants already know about making a test list - so we ask them to make a test list for a state machine with two states and two transitions:

Lift Button State Diagram

Concept - how to TDD a state machine

There is some starting code for a Lift Button. On the branch ‘starting_point_applied_tdd_1’ you will find a partial implementation of a state machine, together with a half-finished test list. The idea is to get the participants going more quickly developing a finite state machine by having them continue from this point.

In this part of the learning hour we need to go through the code, explain what’s already been done, or perhaps better, demo getting to this point.

Concrete

Let the participants take over the code from this point and continue to develop the finite state machine.

Conclusions

Discuss what it was like developing a FSM using TDD. Would this approach scale to larger and more complex state machines?