ROS Tests: catkin_add_executable_with_gtest does not rebuild target
Basically, when I switched from catkin_add_gtest
to add_executable_with_gtest
to make sure the test is invoked only from a .test file, catkin_make no longer recompiles my cpp file with the tests. More detailed explanation below.
I'm trying to run some ROS unit and integration tests. For one of my tests, I added a node that subscribes to some bagged data and uses gtest to assert some simple conditions. Here's what my CMakeLists.txt snippet looked like:
if (CATKIN_ENABLE_TESTING)
find_package(GTest REQUIRED)
catkin_add_gtest(talker-test test/test_talker.cpp)
target_link_libraries(talker-test ${catkin_LIBRARIES})
find_package(rostest REQUIRED)
add_rostest(test/detection_test.test)
endif()
This runs fine. However, I want the test to subscribe to some data from a bag, so I want to run it from a test file. Here's what the test file looks like:
<launch>
<include file="$(find launchdir)/launch/run_bag.launch" />
<!-- Frequency test -->
<param name="hztest1/topic" value="/camera/image" />
<param name="hztest1/hz" value="1.0" />
<param name="hztest1/hzerror" value="0.5" />
<param name="hztest1/test_duration" value="5.0" />
<test test-name="hztest_test" pkg="rostest" type="hztest" name="hztest1" />
<!-- Custom test -->
<test test-name="talker_test" pkg="test_pkg" type="talker-test"/>
</launch>
In order to make sure that my test runs through the .test file and not through my CMakeLists, I modified my CMakeLists file as follows:
if (CATKIN_ENABLE_TESTING)
find_package(GTest REQUIRED)
catkin_add_executable_with_gtest(talker-test test/test_talker.cpp)
target_link_libraries(talker-test ${catkin_LIBRARIES})
find_package(rostest REQUIRED)
add_rostest(test/detection_test.test)
endif()
This results in the behavior I desire (except for the bag running twice- once for each of my tests). But now, if I make changes to testtalker.cpp, running `catkinmake -DCATKINENABLETESTING=true runteststest_pkg` does not recompile the cpp file. How can I make this happen?
Asked by space on 2018-11-28 14:58:22 UTC
Answers
I think you should look into using add_rostest_gtest
to run your ROS related unit tests
if (CATKIN_ENABLE_TESTING)
# set up includes
include_directories(${catkin_INCLUDE_DIRS}
include/
test/include/
)
# find rostest package
find_package(rostest REQUIRED)
# set up the rostest
set(TALKER_ROS_TEST talker_rostest)
add_rostest_gtest(${TALKER_ROS_TEST}
test/detection_test.test
test/test_talker.cpp.cpp
)
# link relevant libraries
target_link_libraries(${TALKER_ROS_TEST}
gtest
gtest_main
${catkin_LIBRARIES}
${PROJECT_NAME}
)
endif()
This links the source gtest file to your .test file, and should solve your problem.
Asked by haelannaleah on 2020-03-24 10:57:25 UTC
Comments