Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to unit test smach state machines?

I'm struggling with how to automate tests to exercise a smach state machine. In particular:

1) Is it possible to start the state machine in a given state? I'm picturing some modification to sm.execute() that sets user data and calls the appropriate execute loop. Or maybe something that specifies the transitions required to get to the desired start state?

2) How can I check that it has transitioned as expected? Note - I'm using smach only, not ROS, but I figured that this was still probably the best place to ask. However, it means that I can't just eavesdrop on the messages that are used to update the smach viewer.

I'm using this state machine to coordinate human and autonomous control; I want to be able to test things like "from any state, joystick override quickly preempts", "from any state, loss of communications triggers preemption and transition to this state".

Has anybody done this before? Is there another way to approach this type of testing?