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

Catkin: run specific unit test

asked 2017-09-18 14:32:28 -0600

mch gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted
1

answered 2017-09-18 16:22:25 -0600

tfoote gravatar image

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

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.
edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2017-09-18 14:32:28 -0600

Seen: 3,527 times

Last updated: Sep 18 '17