Integration Testing: Rostest with non-Catkin Packages (MAVROS and PX4)
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 .bashrc
file 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.
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.
@aau Were you able to find a solution to your problem? I'm currently facing the exact same issue.
@mstampa: No luck so far :( My workaround: Create a test node that publishes dummy data on the same topic as MAVROS.
@micha-sende I had a similar workaround, but unfortunately that's not a viable long-term solution for the parts of the system that matter most to my research. Thanks anyway for the reply! If I get back around to this problem I might post the question on the PX4 forums, maybe someone there has an idea.
I have the same issue when invoking "catkin run_tests", but the ResourceNotFound complaints go away when invoke rostest directly - e.g. rostest <package_name> <test_file_name>