Ask Your Question
0

ROS Tests: catkin_add_executable_with_gtest does not rebuild target

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

space gravatar image

updated 2020-03-24 20:08:21 -0500

jayess gravatar image

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

1 Answer

Sort by ยป oldest newest most voted
0

answered 2020-03-24 10:57:25 -0500

haelannaleah gravatar image

updated 2020-03-24 10:57:53 -0500

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2018-11-28 13:58:22 -0500

Seen: 238 times

Last updated: Mar 24 '20