ROS Tests: catkin_add_executable_with_gtest does not rebuild target

asked 2018-11-28 13:58:22 -0600

space gravatar image

updated 2018-11-28 15:46:19 -0600

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 test_talker.cpp, running catkin_make -DCATKIN_ENABLE_TESTING=true run_tests_test_pkg does not recompile the cpp file. How can I make this happen?

edit retag flag offensive close merge delete