ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

ros2 difference between colcon test and launch_test

asked 2021-04-26 10:03:40 -0500

avzmpy gravatar image

What are appropriate use cases for each one?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
6

answered 2021-04-26 13:14:29 -0500

updated 2021-04-26 13:16:56 -0500

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2021-04-26 10:03:40 -0500

Seen: 834 times

Last updated: Apr 26 '21