ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange |
1 | initial version |
Necroing a bit here, but I had this problem as well and this was my solution
For reference, I refer to unit tests as the library tests (ie: no ROS environment) and integration tests as tests done with rostest
Add in two options in the top of your CMake (or your root CMake)
option(BUILD_UNIT_TESTS "Build the unit tests" OFF)
option(BUILD_INTEGRATION_TESTS "Build the integration tests" OFF)
Write your tests block similar to your above example
if(CATKIN_ENABLE_TESTING)
if(BUILD_UNIT_TESTS)
catkin_add_gtest(
primary_controller_unit_tests
test/unit_tests.cpp
)
if(TARGET primary_controller_unit_tests)
target_link_libraries(
primary_controller_unit_tests
${catkin_LIBRARIES}
${PROJECT_NAME}
)
endif()
endif(BUILD_UNIT_TESTS)
if(BUILD_INTEGRATION_TESTS)
add_rostest_gtest(
primary_controller_integration_tests
test/integration_tests.test
test/integration_tests.cpp
)
if(TARGET primary_controller_integration_tests)
target_link_libraries(
primary_controller_integration_tests
${catkin_LIBRARIES}
${PROJECT_NAME}
)
endif()
endif(BUILD_INTEGRATION_TESTS)
endif(CATKIN_ENABLE_TESTING)
Then when invoking catkin, use
catkin_make run_tests --cmake-args -DBUILD_UNIT_TESTS=OFF -DBUILD_INTEGRATION_TESTS=ON
I'm in the attempt of making a ROS template which will work with GitLab (this sort of functionality makes sense for a CI), if its of any use to anyone else see it here https://github.com/ALTinners/ros-gitlab-ci-example
2 | No.2 Revision |
Necroing a bit here, but I had this problem as well and this was my solution
For reference, I refer to unit tests as the library tests (ie: no ROS environment) and integration tests as tests done with rostest
Add in two options in the top of your CMake (or your root CMake)
option(BUILD_UNIT_TESTS "Build the unit tests" OFF)
option(BUILD_INTEGRATION_TESTS "Build the integration tests" OFF)
Write your tests block similar to your above example
if(CATKIN_ENABLE_TESTING)
if(BUILD_UNIT_TESTS)
catkin_add_gtest(
primary_controller_unit_tests
test/unit_tests.cpp
)
if(TARGET primary_controller_unit_tests)
target_link_libraries(
primary_controller_unit_tests
${catkin_LIBRARIES}
${PROJECT_NAME}
)
endif()
endif(BUILD_UNIT_TESTS)
if(BUILD_INTEGRATION_TESTS)
add_rostest_gtest(
primary_controller_integration_tests
test/integration_tests.test
test/integration_tests.cpp
)
if(TARGET primary_controller_integration_tests)
target_link_libraries(
primary_controller_integration_tests
${catkin_LIBRARIES}
${PROJECT_NAME}
)
endif()
endif(BUILD_INTEGRATION_TESTS)
endif(CATKIN_ENABLE_TESTING)
Then when invoking catkin, use
catkin_make run_tests --cmake-args -DBUILD_UNIT_TESTS=OFF -DBUILD_INTEGRATION_TESTS=ON
I'm in the attempt of making a ROS template which will work with GitLab (this sort of functionality makes sense for a CI), if its of any use to anyone else see it here https://github.com/ALTinners/ros-gitlab-ci-example