Running Tests in ROS 2 from the Command Line - how-to

Running tests from the command line helps verify that ROS packages build correctly and behave as expected. This article explains how to run package tests with colcon, examine test results, and find guidance for debugging failing tests. After following these steps, you will be able to run tests, filter packages, view failures, and find debugging guidance.

Area: debugging, builds, tools | Content type: how-to | Level: intermediate

Prerequisites

You will need a workspace setup with packages that have tests in them.

Build and run your tests

To compile and run the tests, simply run the test verb from colcon at the root of your workspace.

$ colcon test --ctest-args tests [package_selection_args]

Where package_selection_args are optional package selection arguments for colcon to limit which packages are built and run. Find more info in the colcon documentation on Package selection arguments

Sourcing the workspace before testing should not be necessary. colcon test makes sure that the tests run with the right environment, have access to their dependencies, etc.

Examine Test Results

To see the results, simply run the test-result verb from colcon.

$ colcon test-result --all

To see the exact test cases which fail, use the --verbose flag:

$ colcon test-result --all --verbose

Debugging tests with GDB

For detailed guidance on debugging tests using GDB, refer to the GDB Tutorial.