Integration Testing: Rostest with non-Catkin Packages (MAVROS and PX4)

asked 2021-10-08 06:25:04 -0600

aau gravatar image

updated 2021-10-11 02:20:25 -0600

I am trying to run an integration test of a ROS node I wrote that relies on MAVROS.

So I created a rostest which includes a launch file:

<?xml version="1.0"?>
<launch>

    <!-- PX4 SITL and Gazebo vehicle spawn URDF -->
    <include file="$(find px4)/launch/single_vehicle_spawn.launch">
        <arg name="ID" value="0" />
    </include>

    <!-- MAVROS -->
    <include file="$(find mavros)/launch/px4.launch">
        <arg name="fcu_url" value="udp://:14540@localhost:14580" />
    </include>

    <!--  My ROS node -->
    <node pkg="foo" type="bar" name="bar" />

    <!-- Node unit test -->
    <test pkg="foo" type="test_bar" test-name="test_bar" />

</launch>

My CMakeLists.txt:

if(CATKIN_ENABLE_TESTING)
  find_package(rostest REQUIRED)
  add_rostest_gtest(test_${PROJECT_NAME} test/test_${PROJECT_NAME}.test test/test_${PROJECT_NAME}.cpp)
  if(TARGET test_${PROJECT_NAME})
    target_link_libraries(test_${PROJECT_NAME} ${catkin_LIBRARIES})
  endif()
endif()

I try to run the test using catkin tools:

$ catkin run_tests

However, I'm getting a ResourceNotFound error:

rospkg.common.ResourceNotFound: px4

I guess the problem is that PX4 is neither a catkin package nor part of the ROS_PACKAGE_PATH. In order to run simulations normally, using roslaunch, I set the required environment variables in my .bashrcfile like so:

source /home/ros/workspaces/px4/Tools/setup_gazebo.bash /home/ros/workspaces/px4 /home/ros/workspaces/px4/build/px4_sitl_default > /dev/null
export ROS_PACKAGE_PATH=$ROS_PACKAGE_PATH:/home/ros/workspaces/px4:/home/ros/workspaces/px4/Tools/sitl_gazebo

This allows to execute simulations:

$ roslaunch foo bar.launch

Apparently, this environment is not passed to the rostest.

Does anybody have an idea on this?

The only things I stumbled upon during my research is

Both did not help me with my problem though.

edit retag flag offensive close merge delete

Comments

My experience with catkin tests is that they have a lot of problems with external resources since they don't load paths as usual ros operation does.

Mermy gravatar image Mermy  ( 2021-10-11 05:32:21 -0600 )edit