0

Rosanswers logo

I know there are specific test commands catkin_make run_tests to run all tests and catkin_make run_tests_<projectname>_gtest_<testname> to run specific test declared by catkin_add_gtest(<testname> …)

One test file can have multiple tests though. Example:

TEST(testsuit1, test1) {
..
}

TEST(testsuit1, test2) { .. }

TEST(testsuit2, test3) { .. }

int main(int argc, char **argv) { testing::InitGoogleTest(&argc, argv); return RUN_ALL_TESTS(); }

Is that possible to run only testsuit1 or only test3 from my example?


Originally posted by mch on ROS Answers with karma: 46 on 2017-09-18

Post score: 2

1 Answers1

0

Rosanswers logo

I'm not familiar with a way to do that specifically from catkin_make level as it would not make much sense to pass the same argument to all gtests.

But if you just run the specific test directly and then use the --gtest_filter option: https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-a-subset-of-the-tests

For example in tf2 there's a gtest callted test_cache_unittest that can be run with the filter and without like this.

. devel/setup.bash
tfoote@snowman:~/work/workspaces/geometry Last: [127] (0s Seconds)
$ ./devel/lib/tf2/test_cache_unittest --gtest_filter=Bullet*
Note: Google Test filter = Bullet*
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from Bullet
[ RUN      ] Bullet.Slerp
[       OK ] Bullet.Slerp (0 ms)
[----------] 1 test from Bullet (0 ms total)

[----------] Global test environment tear-down [==========] 1 test from 1 test case ran. (1 ms total) [ PASSED ] 1 test.

And without the filter you can see it running more tests.

tfoote@snowman:~/work/workspaces/geometry Last: [0] (0s Seconds)
$ ./devel/lib/tf2/test_cache_unittest
[==========] Running 8 tests from 2 test cases.
[----------] Global test environment set-up.
[----------] 7 tests from TimeCache
[ RUN      ] TimeCache.Repeatability
[       OK ] TimeCache.Repeatability (1 ms)
[ RUN      ] TimeCache.RepeatabilityReverseInsertOrder
[       OK ] TimeCache.RepeatabilityReverseInsertOrder (0 ms)
[ RUN      ] TimeCache.ZeroAtFront
[       OK ] TimeCache.ZeroAtFront (0 ms)
[ RUN      ] TimeCache.CartesianInterpolation
[       OK ] TimeCache.CartesianInterpolation (4 ms)
[ RUN      ] TimeCache.ReparentingInterpolationProtection
[       OK ] TimeCache.ReparentingInterpolationProtection (0 ms)
[ RUN      ] TimeCache.AngularInterpolation
[       OK ] TimeCache.AngularInterpolation (11 ms)
[ RUN      ] TimeCache.DuplicateEntries
[       OK ] TimeCache.DuplicateEntries (0 ms)
[----------] 7 tests from TimeCache (16 ms total)

[----------] 1 test from Bullet [ RUN ] Bullet.Slerp [ OK ] Bullet.Slerp (0 ms) [----------] 1 test from Bullet (0 ms total)

[----------] Global test environment tear-down [==========] 8 tests from 2 test cases ran. (16 ms total) [ PASSED ] 8 tests.


Originally posted by tfoote with karma: 58457 on 2017-09-18

This answer was ACCEPTED on the original site

Post score: 1

Tully
  • 24,992
  • 1
  • 17
  • 35