Test Framework in ROS2

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.