ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A answers.ros.org
Ask Your Question
5

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 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: http://pastebin.com/raw.php?i=JVV8QfXA .

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
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 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
3

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 imageDavid Lu ( 2014-07-01 16:05:40 -0500 )edit

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

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

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 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

Question Tools

1 follower

Stats

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

Seen: 2,332 times

Last updated: Jul 01 '14