Grouping tests by googletest categories by categories

Can googletest unit tests be grouped into categories? For example, "SlowRunning", "BugRegression", etc. The closest I found is the -gtest_filter option. By adding / adding category names to test or instrument names, I can simulate the existence of groups. This does not allow me to create groups that usually do not start.

If categories do not exist in googletest, is there a way around good or best practice?

Edit: Another way is to use -gtest_also_run_disabled_tests. Adding DISABLED_ before the tests gives you exactly one conditional category, but I feel like I'm abusing DISABLED when I do this.

+6
source share
2 answers

One use case for gtest_filter and use a naming convention for tests (as you describe in the question).

TEST_F(Foo, SlowRunning_test1) {...} TEST_F(Foo, BugRegression_test1) {...} TEST_F(Foo, SlowRunningBugRegression_test1) {...} 

Another way to use separate executables / executables for any type of test. This method has some limitations because gtest uses static auto-registration, so if you include some source file, all tests implemented in this source file will be included in the generated binary / executable file.

In my opinion, the first method is better. In addition, I would perform a new macro registration test to 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 
+3
source

The only way to run a subset of tests in a single test executable is --gtest_filter. There are two ways to work around integration test and unit test solutions.

  • Use a naming convention such as Integration.Testname and Unit.Testname. In addition to this, I would also support script files, such as RunIntegration.bat and RunUnit.bat, to run from build automation scripts for different scripts.
  • Support test executables for integration, units or other categories. In visual studios in each of them there will be separate projects.
+2
source

Source: https://habr.com/ru/post/926346/


All Articles