Robotics StackExchange | Archived questions

Writing tests in ROS 2

Hi,

I have a large number of tests in ROS 2 in Python I would like to write that are essentially 1. Publish a message 2. Subscribe and do something 3. Check what happens during the "do something"

I can do this by creating the publisher and subscriber in the same piece of code. However, it's closer to what happens "for real" if I publish in one process and subscribe in another. But that doesn't fit in well with pytest. Is there a ROS 2 "way" to do this - something like the equivalent of ROS1's rostest?

Thanks!

Asked by jbarry on 2023-03-09 15:00:42 UTC

Comments

Answers

I’m thinking that the important thing to test is the “do something” code, and not ROS’s publish and subscribe mechanisms (or the little bit of probably-not-going-to-change-very-often client code that calls them). To test the “do something” code, I’d be inclined to write a set of tests where each test constructs a different message (the data structure), passes it to your “do something” code as input, and verifies whatever the “do something” code produces in response. Would that serve your objectives?

Asked by stevebillings on 2023-03-10 20:49:03 UTC

Comments

I do test the "do something" code separately of course. But if I leave the wrappers untested then the only way I find bugs in them is by starting up a whole pipeline. This is especially bad with ROS2's emphasis on asynchronicity where multi-process tests can be very helpful to track down race conditions and deadlocks without having to start a whole simulator or run on hardware.

Asked by jbarry on 2023-03-13 07:22:48 UTC