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

How to run multiple rostests with one .test file and one gtest test case

asked 2018-11-20 12:59:14 -0600

aswin gravatar image

updated 2018-11-20 14:55:18 -0600

I have a gtest test case that can be launched from a rostest .test file. I would like to run the same test with multiple parameters.

I came across using ARG in cmake we can set multiple params for the .test file, but can we use the same test file with different parameters to run the same tests with different inputs? i.e. different tests with same ${launch_file} and varying args

    DEPENDENCIES ${target}
    ARGS ...

In a more generic sense, would we be able to run parametrised rostests like eg. Gtest::Combine

edit retag flag offensive close merge delete


I just realized that if the first ARG is the same, then the output file where results are stored are same. Not sure if this was intended

aswin gravatar image aswin  ( 2018-11-20 14:55:30 -0600 )edit

1 Answer

Sort by » oldest newest most voted

answered 2018-11-20 14:05:36 -0600

updated 2018-11-22 09:12:17 -0600

If I understand your situation, it shouldn't be too hard to have a single .test file and single gtest binary, and then pass in different sets of parameters using something like add_rostest(check_thing.test ARGS case:=foo), where your check_thing.test file is something like (and you've compiled the check_thing binary separately using add_executable):

  <arg name="case" />
  <test test-name="check_thing_case_$(arg case)" pkg="my_fancy_package" type="check_thing">
    <rosparam command="load" file="$(find my_fancy_package)/test/$(arg case).yaml" />

However, this does incur the time cost of starting and stopping ROS for each case. If you don't actually need a fresh slate each time, it might make more sense to just build these different cases into your GTest binary— basically, use the ros::NodeHandle::setParam API to set the parameters you need for your different cases and invoke the tests. Or, even easier, load all sets of parameters in different namespaces, and then when you go to test your object, pass it NodeHandle instances pointing at the different namespaces so that it will see different sets of parameters when it goes to initialize itself.

edit flag offensive delete link more


Thank you for the response.

Yes right now I am using something like add_rostest(check_thing.test ARGS case:=foo) multiple times. There doesnt seem to be an easy way to do this for add_rostest_gtest. Will open a PR if I figure this out.

aswin gravatar image aswin  ( 2018-11-20 14:52:22 -0600 )edit

I was using the ros::NodeHandle::getParam, but unfortunately I am using gazebo and require a fresh state each time. Restarting gazebo and dependant environment nodes doesnt play well with ros::Time and tf

aswin gravatar image aswin  ( 2018-11-20 14:54:15 -0600 )edit

Use of add_rostest_gtest specifically assumes a 1:1 mapping of tests to gtest binaries, which is not the case for you. So you have to compile your binary separately.

mikepurvis gravatar image mikepurvis  ( 2018-11-22 09:09:56 -0600 )edit

FWIW, add_rostest_gtest was added later as an optimization for this common case. The old way was to _always_ compile your test binaries separately. For the full history lesson, see:

mikepurvis gravatar image mikepurvis  ( 2018-11-22 09:11:19 -0600 )edit

Thank you. I finally followed the example in this function and added numerous arguments for the same test

aswin gravatar image aswin  ( 2018-11-22 09:45:27 -0600 )edit

Question Tools



Asked: 2018-11-20 12:59:14 -0600

Seen: 1,239 times

Last updated: Nov 22 '18