Skip to content

Commit

Permalink
Add launch test using ros parameter (#29)
Browse files Browse the repository at this point in the history
---------

Co-authored-by: Bilal Gill <[email protected]>
  • Loading branch information
griswaldbrooks and bgill92 authored Sep 17, 2023
1 parent bafcc87 commit 3e9df5b
Show file tree
Hide file tree
Showing 3 changed files with 544 additions and 0 deletions.
5 changes: 5 additions & 0 deletions functional_programming_tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ ament_target_dependencies(main rclcpp std_msgs example_srvs)
if(BUILD_TESTING)
find_package(ament_cmake_gtest REQUIRED)
find_package(ament_cmake_gmock REQUIRED)
find_package(launch_testing_ament_cmake REQUIRED)
ament_add_gtest(with_functional_programming test/with_functional_programming.cpp TIMEOUT 5)
ament_target_dependencies(with_functional_programming rclcpp std_msgs)

Expand All @@ -25,6 +26,10 @@ if(BUILD_TESTING)

ament_add_gmock(with_dependency_injection test/with_dependency_injection.cpp TIMEOUT 5)
ament_target_dependencies(with_dependency_injection rclcpp std_msgs example_srvs)

ament_add_gtest_executable(with_parameters test/with_parameters.cpp)
ament_target_dependencies(with_parameters rclcpp std_msgs example_srvs)
add_launch_test(test/launch/with_parameters.test.py TIMEOUT 120 ARGS "test_binary_dir:=${CMAKE_CURRENT_BINARY_DIR}")
endif()

ament_package()
54 changes: 54 additions & 0 deletions functional_programming_tests/test/launch/with_parameters.test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# -*- coding: utf-8 -*-
import launch
from launch_ros.actions import Node
import launch_testing
import unittest


def generate_test_description():

with_parameters_test = Node(
executable=launch.substitutions.PathJoinSubstitution(
[
launch.substitutions.LaunchConfiguration("test_binary_dir"),
"with_parameters",
]
),
output="screen",
emulate_tty=True,
parameters=[
{"robot_size": 1},
],
)

return launch.LaunchDescription(
[
launch.actions.DeclareLaunchArgument(
name="test_binary_dir",
description="Binary directory of package "
"containing test executables",
),
with_parameters_test,
# In tests where all of the procs under tests terminate themselves, it's necessary
# to add a dummy process not under test to keep the launch alive. launch_test
# provides a simple launch action that does this:
# https://github.com/ros2/launch/blob/aed025e04e0b143362c69bf29a67b2ffff4c59ee/launch_testing/test/launch_testing/examples/args_launch_test.py#L63
launch_testing.util.KeepAliveProc(),
launch_testing.actions.ReadyToTest(),
]
), {
"with_parameters_test": with_parameters_test,
}


class TestGTestWaitForCompletion(unittest.TestCase):
# Waits for test to complete, then waits a bit to make sure result files are generated
def test_gtest_run_complete(self, with_parameters_test):
self.proc_info.assertWaitForShutdown(with_parameters_test, timeout=4000.0)


@launch_testing.post_shutdown_test()
class TestGTestProcessPostShutdown(unittest.TestCase):
# Checks if the test has been completed with acceptable exit codes
def test_gtest_pass(self, proc_info, with_parameters_test):
launch_testing.asserts.assertExitCodes(proc_info, process=with_parameters_test)
Loading

0 comments on commit 3e9df5b

Please sign in to comment.