ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org

Test Framework in ROS2

I could not find any information about a “ROS node unit and integration” test framework in ROS2 (an equivalent to rostest in ROS1).

According to Developer Guide - Testing (ros2 wiki) “Library unit testing (level 1)” is done with gtest, unittest, nosetest (mainline C++ and Python) like in ROS1.

But what about “ROS node unit testing (level 2)” and “ROS node integration testing (level 3)”? In ROS1 people ended up to develop custom solutions to do ROS node unit and integration testing because the restrictions and lack of useability of rostest, lack of generic tests nodes, etc.

BTW: In ROS2 new Package Categories are used to define requirements w.r.t. to testing specific to the “criticality” of ROS2 packages. I like that concept…

ROS 2 tries to be less opinionated than ROS 1. While gtest, unittest, and nosetest are supported (and heavily used to test ROS 2 code) they are not the only way. Integration with these tools is optional. E.g. ROS 2 also supports gmock (which ROS 1 doesn’t do because of its difficult interaction with gtest when packaged separately). All of these testing frameworks are integrated using different ROS 2 packages. So adding support for more should be straight forward.

At the moment we are using ROS 2 launch files as a replacement to an explicit rostest command. The package launch_testing provides a few different ways to check the result of a test node. This can be either a simple return code of one process (which decides on the result of the launch file and tears down all the other processes) or it could rely on specific output to be printed (matched by plain strings or regex). While the current syntax and API is everything but pretty it is functional and we use that to cover a lot of ROS 2 code. E.g. the demo_nodes_cpp providing simple talker, listener and services are tested using that. Since the same launch file template is being used for multiple cases in this package it is a bit more complicated but it should provide an idea what is possible and how it works.

That’s great!

Is it possible to integrate other “coverage determination” frameworks than the usual gcov which provide more advanced coverage measurements as well?

You should be able to integrate any framework you like. I don’t see where ROS 2 would prohibit you from doing so. ROS 2 is basically just a bunch of CMake packages - so anything you can do with a CMake package should be doable.

1 Like