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

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 add_rostest(${launch_file}
DEPENDENCIES ${target} ARGS ...  In a more generic sense, would we be able to run parametrised rostests like eg. Gtest::Combine edit retag close merge delete ## Comments 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 ( 2018-11-20 14:55:30 -0500 )edit ## 1 Answer Sort by » oldest newest most voted 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): <launch> <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" />
</test>
</launch>


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.

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.

( 2018-11-20 14:52:22 -0500 )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

( 2018-11-20 14:54:15 -0500 )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.

( 2018-11-22 09:09:56 -0500 )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: https://github.com/ros/ros_comm/issue...

( 2018-11-22 09:11:19 -0500 )edit

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

( 2018-11-22 09:45:27 -0500 )edit