ros2 difference between colcon test and launch_test
What are appropriate use cases for each one?
ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
What are appropriate use cases for each one?
launch_test
is a command that is provided by the launch_testing
package. It can be used to run tests that are described/set up using a launch file, e.g.
$ launch_test path/to/my_launch_test.py
The test must be set up in a very specific way. The Python launch file must define a generate_test_description()
function that returns a LaunchDescription
. I don't think this file needs to be part of a package; it might be able to just be a standalone file. For example:
def generate_test_description():
return launch.LaunchDescription([
launch.actions.ExecuteProcess(
cmd=[path_to_process],
),
# Start tests right away - no need to wait for anything in this example.
# In a more complicated launch description, we might want this action happen
# once some process starts or once some other event happens
launch_testing.actions.ReadyToTest()
])
See this README: https://github.com/ros2/launch/blob/3....
colcon test
is a command that runs all tests for a given package (or given packages): C++ tests (e.g. defined as a CMake test in a CMakeLists.txt
using ament_add_gtest(...)
), or Python tests (e.g. defined as a CMake test in a CMakeLists.txt
using ament_add_pytest_test(...)
or just a Python file under a test/
directory in a pure Python package). E.g.
$ colcon test --packages-select my_package
Some of those Python test files can be launch tests similar to the example above, but the generate_test_description()
function has to be annotated with @pytest.mark.launch_test
for the test file to be run properly. I think in this case the same file can also be run using launch_test
.
In general, you can simply just use colcon test
to run your tests.
Asked: 2021-04-26 10:03:40 -0500
Seen: 910 times
Last updated: Apr 26 '21
rostest & Python - Multiple Test Fixtures In Single File
Testing with rosmake -a -t fails because a test failure failed to launch. What's wrong?
Testing with rosmake -a -t fails because a test did not run. What's wrong?
Simple test if Ros was installed correctly?
How can I run stacks tests with valgrind?
rosbuild_add_roslaunch_check(..) and required arguments
rosjava_core compilation on OS X - one test fails: testCreatePublic [closed]
How do I conditionally include a catkin component only for testing?