I believe that HSMs are ideal for Test Driven Development (TDD). A state machine is in fact a way of expressing constraints of the system behavior. In other words, a state machine is a very effective “spaghetti” reducer. This means that instead of testing combinatorial-explosion of different paths through the “spaghetti” code, you test only a handful of explicitly known states. You can easily test state machine reactions to all events in all states.
Perhaps the biggest problem is with testing guards, exactly because guards are the IFs and ELSEs, which make testing of traditional sequential code so difficult. That’s why well-structured state machines use guards sparingly.
One example of testing an HSM is the QHsmTst application (http://www.state-machine.com/resources/goodies.htm#QHSM). This example provides an exhaustive test of the QEP event processor. Note that this example does not exhaustively test the state machine itself, but the idea is the same.