ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
8

rostest - Minimum Working Example

asked 2014-07-01 10:20:47 -0500

David Lu gravatar image

updated 2014-07-01 10:27:40 -0500

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.

edit retag flag offensive close merge delete

Comments

It just doesn't even try to build the executable? Or the build fails?

fergs gravatar image fergs  ( 2014-07-01 12:24:58 -0500 )edit

Did you pass `run_tests` as a make target when building?

William gravatar image William  ( 2014-07-01 13:04:15 -0500 )edit

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 .

David Lu gravatar image David Lu  ( 2014-07-01 13:37:22 -0500 )edit

(compiled with run_tests)

David Lu gravatar image David Lu  ( 2014-07-01 13:37:38 -0500 )edit
1

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?

galou gravatar image galou  ( 2015-01-06 10:20:08 -0500 )edit

The answer to my own question is "find_package(rostest REQUIRED)"

galou gravatar image galou  ( 2015-01-06 10:33:43 -0500 )edit

You should also wrap all testing stuff in a conditional block as mentioned in the other answer.

Dirk Thomas gravatar image Dirk Thomas  ( 2015-01-06 11:57:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2014-07-01 16:01:52 -0500

fergs gravatar image

Your node is called "tests_mynode" (with an S on test) and the launch file loads type "test_mynode" (no S). Fix the launch and all worked on my system under hydro.

edit flag offensive delete link more

Comments

Fair enough. :)

David Lu gravatar image David Lu  ( 2014-07-01 16:05:40 -0500 )edit
2

Full minimum working example here: https://gitlab.com/InstitutMaupertuis...

VictorLamoine gravatar image VictorLamoine  ( 2017-02-01 13:31:40 -0500 )edit

@VictorLamoine under what license do you distribute the example code?

thinwybk gravatar image thinwybk  ( 2017-05-16 14:20:24 -0500 )edit

@thinwybk BSD, https://gitlab.com/InstitutMaupertuis... . Do whatever you want it with!

VictorLamoine gravatar image VictorLamoine  ( 2017-05-17 01:57:40 -0500 )edit

@VictorLamoine Great. Thanks a lot.

thinwybk gravatar image thinwybk  ( 2017-05-17 14:28:58 -0500 )edit
2
gocarlos gravatar image gocarlos  ( 2017-10-03 08:52:06 -0500 )edit
6

answered 2014-07-01 16:08:10 -0500

Dirk Thomas gravatar image

updated 2014-07-01 16:08:46 -0500

Another side note: your CMakeLists.txt file should look more like this:

if(CATKIN_ENABLE_TESTING)
  find_package(rostest REQUIRED)
  add_rostest_gtest(tests_mynode test/alaunch.launch test/mytest.cpp)
  target_link_libraries(tests_mynode ${catkin_LIBRARIES})
endif()
edit flag offensive delete link more

Comments

A fair point. I took it out because I wanted it to build more, not less.

David Lu gravatar image David Lu  ( 2014-07-01 16:34:49 -0500 )edit

Question Tools

4 followers

Stats

Asked: 2014-07-01 10:20:47 -0500

Seen: 11,385 times

Last updated: Jul 01 '14