Writing rostest files

Test nodes

In order to create a rostest, you first need to write some test nodes. Test nodes are nodes that also execute unit tests. To date, we have used both the C++ gtest framework and the Python unittest framework within rostest. Nodes written with gtest are 100% compatible with rostest; Python unittests require an extra wrapper.

File format

rostest files are 100% compatible with roslaunch. These files generally have a .test or .launch file extension.

It's highly recommended that you embed tests within your roslaunch files in order to verify that they are functioning properly. The difference between rostest and roslaunch is that rostest also processes <test> tags within your XML file. These <test> tags specify test nodes to run.

<test> tag

Please see <test> tag reference

Running your rostest with 'make test'/CMakeLists.txt

You can easily add a rostest to your CMake build using the rosbuild_add_rostest(test_file) command (documentation) in your CMakeLists.txt file.

Using the ROS-specific cmake build commands is highly recommended as it enables you to do useful test commands such as testing all packages that depend on your package.

This is how you might want to set up the test in your CMakeLists.txt (assuming that your test is using gtest):

# add the test executable, keep it from being built by "make all"
rosbuild_add_executable(test_mynode EXCLUDE_FROM_ALL src/test/test_mynode.cpp)

# Link test_mynode against gtest and add a dependency to the "test" target
rosbuild_add_gtest_build_flags(test_mynode)

# Make sure rostest launches test/mynode.test during "make test"
rosbuild_add_rostest(test/mynode.test)

If you run make test on the command line now, the test binary will get compiled and the rostest file 'test/mytest.test' will be launched by rostest.

Example rostest files

Here is a very simple rostest file, which you'll note is compatible with the roslaunch format:

<launch>
  <node pkg="mypkg" type="mynode" name="mynode" />
  <test test-name="test_mynode" pkg="mypkg" type="test_mynode" />
</launch>

This launch file will start mynode and then run the test_mynode test node.

Here's another rostest file that uses rostest to initialize the parameter server:

<launch>
  <param name="string"  value="mystring" />
  <test test-name="test_string_params" pkg="somepackage" type="test_string_param.py" />
</launch>

Wiki: rostest/Writing (last edited 2012-01-16 11:49:57 by StephanWirth)