rostest - Minimum Working Example
I'm having problems developing tests for a package with catkin, specifically tests that run within a launch file using C++/gtest.
You can download my files here.
CMakeLists.txt
cmake_minimum_required(VERSION 2.8.3)
project(davidscheck)
find_package(catkin REQUIRED COMPONENTS roscpp)
catkin_package()
include_directories(
${catkin_INCLUDE_DIRS}
)
find_package(rostest REQUIRED)
find_package(gtest)
add_rostest_gtest(tests_mynode test/alaunch.launch test/mytest.cpp)
target_link_libraries(tests_mynode ${catkin_LIBRARIES} ${GTEST_LIBRARIES})
test/alaunch.launch
<launch>
<test test-name="test_mynode" pkg="davidscheck" type="test_mynode" />
</launch>
teset/mytest.cpp
#include <gtest/gtest.h>
TEST(DavidsTester, basicTest){
EXPECT_TRUE(true);
}
int main(int argc, char** argv){
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
Problem: The executable is not being built.
Note that I do want it to run within the launch file, so adding catkin_add_gtest
will not work.
It just doesn't even try to build the executable? Or the build fails?
Did you pass `run_tests` as a make target when building?
Slight correction: The executable is being built, but the launch file cannot find it. Output snippet is here: http://pastebin.com/raw.php?i=JVV8QfXA .
(compiled with run_tests)
I cannot run your example with indigo. CMake cannot find the package gtest: "Could not find a package configuration file provided by "gtest""
If I remove it, I get no error. But if I remove your package from my workspace I get the error "Unknown CMake command "add_rostest_gtest"". What do I miss?
The answer to my own question is "find_package(rostest REQUIRED)"
You should also wrap all testing stuff in a conditional block as mentioned in the other answer.