ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

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.


cmake_minimum_required(VERSION 2.8.3)

find_package(catkin REQUIRED COMPONENTS roscpp)



find_package(rostest REQUIRED)

add_rostest_gtest(tests_mynode test/alaunch.launch test/mytest.cpp)
target_link_libraries(tests_mynode ${catkin_LIBRARIES} ${GTEST_LIBRARIES})


 <test test-name="test_mynode" pkg="davidscheck" type="test_mynode" />


#include <gtest/gtest.h>

TEST(DavidsTester, basicTest){

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


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

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

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

William gravatar imageWilliam ( 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: .

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

(compiled with run_tests)

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

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 imagegalou ( 2015-01-06 10:20:08 -0500 )edit

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

galou gravatar imagegalou ( 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 imageDirk Thomas ( 2015-01-06 11:57:21 -0500 )edit

2 Answers

Sort by ยป oldest newest most voted

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


Fair enough. :)

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

Full minimum working example here:

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

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

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

@thinwybk BSD, . Do whatever you want it with!

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

@VictorLamoine Great. Thanks a lot.

thinwybk gravatar imagethinwybk ( 2017-05-17 14:28:58 -0500 )edit

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:

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


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

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

Your Answer

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

Add Answer

The deadline to submit a proposal to present at ROSCon 2017 is June 25, 2017. Submit yours now!

Question Tools



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

Seen: 2,695 times

Last updated: Jul 01 '14