How to best call catkin_add_gtest and add_rostest_gtest separately?
I'm trying to test ROS code at two different levels (calling catkin_add_gtest
and add_rostest_gtest
separately), and I haven't found documentation on exactly how to do what I'm hoping to do.
Essentially, I have src/library.cpp
that I'd want to run gtest
tests on through test/test_library.cpp
. This should test low-level functionality - just the methods and functions defined in library.cpp
, without any need of having a node running or publishing/subscribing.
I'd also like to run a full-fledged node-level test, running multiple nodes through rostest
(defined in a test/test_node.test
file), spun up through a gtest
node defined in test/test_node.cpp
.
The problem I'm facing is that if I run catkin run_tests package_name
, this runs both the catkin_add_gtest
and add_rostest_gtest
targets. I'd like to use some command to run only one or the other, not both. How might I do that?
See example CMakeLists.txt
below.
# CMakeLists.txt
...
add_library(library src/library.cpp )
target_link_libraries(library ${catkin_LIBRARIES})
if(CATKIN_ENABLE_TESTING)
if(TARGET run_library_test) # can I do this?
find_package(catkin REQUIRED rostest)
catkin_add_gtest(test_library test/test_library.cpp)
target_link_libraries(test_library library ${catkin_LIBRARIES})
endif() # run_library_test
if(TARGET run_node_test) # can I do this?
find_package(catkin REQUIRED rostest)
add_rostest_gtest(test_node test/test_node.test test/test_node.cpp)
target_link_libraries(test_node library ${catkin_LIBRARIES})
endif() # run_node_test
endif() # CATKIN_ENABLE_TESTING