statechart unit testing
Hi All, I have statechart implementation that I have spread over multiple translation units - I would like to unit test the control logic by inserting mock transition actions. The library is explicitly designed not to be dynamic - Can anyone suggest a way I could accomplish this - Its also likely that I could reuse the statechart control logic with different implementations of transition actions so if it is possible to inject this dependency I can reuse the code. Thanks Sean
Hi Sean
I have statechart implementation that I have spread over multiple translation units - I would like to unit test the control logic by inserting mock transition actions. The library is explicitly designed not to be dynamic - Can anyone suggest a way I could accomplish this -
You could have the transition actions call functions of an abstract base class, derivations of which can be passed to the state machine ctor or even set dynamically.
Its also likely that I could reuse the statechart control logic with different implementations of transition actions so if it is possible to inject this dependency I can reuse the code.
For better reuse, I personally often use template parameters. See e.g. http://www.boost.org/libs/statechart/doc/tutorial.html#SubmachinesAndParamet.... If you need variability with transition actions, you could also pass member function pointers as template arguments. This is the compile-time alternative to the abstract base class above. HTH, -- Andreas Huber When replying by private email, please remove the words spam and trap from the address shown in the header.
participants (2)
-
Andreas Huber
-
Sean Kelly