2

I'm looking for a way to execute (for unit-testing purposes) only fractions of a complex state -machine. For that purpose I'm evaluating boost::statechart framework.

One way that I considered was to design a hierarchical state machine, where each state is defined as a nested state-machine, that should be tested separately.

Consider the FSM definition from the following code snippet:

struct Fsm: boost::statechart::state_machine< Fsm, StateA >
{
  ...
}

struct StatA : boost::simple_state< StateA, Fsm, StateA1 >
{
  ...
}

struct StateB : boost::simple_state< StateB, Fsm, StateB1 >  
{
  ....
}

struct StateA1 : boost::simple_state< StateA1, StateA >
{
  ....
}

struct StateA2 : boost::simple_state< StateA2, StateA >
{
  ....
}

struct StateB1 : boost::simple_state< StateB1, StateB >  
{
  ....
}

struct StateB2 : boost::simple_state< StateB2, StateB >  
{
  ....
}

Is it possible to unit-test the logic defined inside state B i.e. B1 and B2 inner states, without executing or even compiling the logic defined for state A including its inner A1 and A2 states?

Thanks in advance, AmirH

  • You can't compile inner states w/o compiling the outer ones, but you can extract FSM-independant code out of the states, move it to free functions, and then test these functions. – Igor R. Oct 23 '12 at 15:28
  • Thanks Igor. But what if for unit-test purpose I'll replace StateB with StateB_Test i.e. struct StateB_Test: boost::statechart::state_machine? The only problem is that I need to correlate StateB1 & StateB2 to StateB_Test. Any ideas? – Amir Halperin Oct 24 '12 at 08:09

0 Answers0