Can googletest unit tests be grouped by categories? For example "SlowRunning", "BugRegression", etc. The closest thing I have found is the --gtest_filter option. By appending/prepending category names to the test or fixture names I can simulate the existence of groups. This does not allow me to create groups that are not normally run.
If categories do not exist in googletest, is there a good or best practice workaround?
Edit: Another way is to use the --gtest_also_run_disabled_tests. Adding DISABLED_ in front of tests gives you exactly one conditional category, but I feel like I'm misusing DISABLED when I do it.
TEST_F(TestFixtureName, TestName) { ... statements ... } Defines an individual test named TestName that uses the test fixture class TestFixtureName . The test suite name is TestFixtureName .
gMock is a library (sometimes we also call it a “framework” to make it sound cool) for creating mock classes and using them. It does to C++ what jMock/EasyMock does to Java (well, more or less).
To run all the tests in a default group, choose the Run icon and then choose the group on the menu. Select the individual tests that you want to run, open the right-click menu for a selected test and then choose Run Selected Tests (or press Ctrl + R, T).
One of way use gtest_filter option and use naming convention for tests (as you describe in question).
TEST_F(Foo, SlowRunning_test1) {...}
TEST_F(Foo, BugRegression_test1) {...}
TEST_F(Foo, SlowRunningBugRegression_test1) {...}
Other way use separate binaries/executable for any type of test. This way have some limitations because gtest use static autoregistration so if you include some source file - all tests implemented in this source file would be included to generated binary/executable.
By my opinion first method better. Additionally, i would implemented new test registration macro for make my life easier:
#define GROUP_TEST_F(GroupName, TestBase, TestName) \
#ifdef NO_GROUP_TESTS \
TEST_F(TestBase, TestName) \
#else \
TEST_F(TestBase, GroupName##_##TestName) \
#endif
The only way to run subset of tests in a single test executable is --gtest_filter. There are two workarounds to executing say integration tests and unit tests
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With