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

[ROS2][foxy][launch testing] Integration testing with launch testing

asked 2021-05-05 10:21:04 -0600

anastasiaPan gravatar image

updated 2021-05-05 10:22:51 -0600

I would like to do integration test using I have based my self on the examples ( and I can launch the node and run unittest.TestCase but I am not sure how to check the output. All I can find is the launch_testing.asserts funcitons but it looks like I can only test exit codes and strings? I would like to test:

  • a response from a service call
  • a result from a published topic

Example of my code - currently I am only trying to test the response from the service: I can see that the node is launched and the service is called but I am not able to test the response

    import os
    import sys
    import unittest
    import launch.actions
    import launch.substitutions
    import lifecycle_msgs.msg
    import ament_index_python
    import launch_ros.actions
    import launch_testing
    import launch_testing.actions
    import pytest

    from launch import LaunchDescription
    from launch import LaunchService
    from launch.actions import ExecuteProcess
    from launch_ros.actions import Node
    from launch_testing.legacy import LaunchTestService                                                                                                           
    from my_srv_pkg.srv import MySrv
    from launch_testing.asserts import assertSequentialStdout

    def generate_test_description():
        TEST_PROC_PATH = os.path.join(

        # This is necessary to get unbuffered output from the process under test
        proc_env = os.environ.copy()
        proc_env['PYTHONUNBUFFERED'] = '1'

        launch_node = launch.actions.ExecuteProcess(
            cmd=['ros2 launch my-pkg'],
            env=proc_env, output='screen'

    return launch.LaunchDescription([

class TestServiceCall(unittest.TestCase):
    def test_if_service_is_called(self, proc_output):
        call_service_action = ExecuteProcess(
        cmd=['ros2 service call /my_service my-pkg/srv/MySrv "{<request data>}"'],

            response = MySrv.Response()
            <populate response with expected value>

            # here I want to check the response - if it is the same to what I expect  
            proc_output.assertWaitFor(response, timeout=5)
edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted

answered 2022-07-25 04:36:37 -0600 gravatar image

As i run into the same problem i created two example packages for testing a node that publishes a text and a pointcloud2 message. Maybe the packages can be of some help.

Testing a node that receives a string and republishes it:

Testing a node that receives a Pointcloud2 message and republishes it:

edit flag offensive delete link more

answered 2022-03-11 13:37:50 -0600

bojankoce gravatar image

Hello, @anastasiaPan.

Some illustrative examples about ROS2 unit and integration testing can be found in this document.

Did you find some more learning resources in the meantime? I am also interested in this topic.

Cheers, Bojan.

edit flag offensive delete link more

Question Tools



Asked: 2021-05-05 10:21:04 -0600

Seen: 796 times

Last updated: Jul 25 '22