Return to Website   
Quantum Leaps Discussion Forum

Search the Forum for answers or post your questions to the
Quantum Leaps community



Return to Website

  Reply
  Forum

Subject:   Re: Any good patterns for testing HSMs?
Name:   Miro Samek
Date Posted:   Jul 27, 08 - 11:39 PM
Email:   miro@quantum-leaps.com
Website:   http://www.state-machine.com
Message:   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.

Miro
   


  Reply
  Forum


powered by Powered by Bravenet bravenet.com