googletestgcov

googletest - command line option to execute "the first, the second, etc"


I'm using gcov and I'd like to gather coverage results on a per test case basis.

QUESTION
When I execute the googletest executable, is it possible to pass in an argument on command line that says execute only the Nth test case?

I'd even be ok with passing in the name of the fixture+case; I can just use Python with regex to pull out all the tests.

Obviously I can accomplish the same thing by having one test case per .cpp file but that sounds ... stupid.


Solution

  • googletest allows to run a single test case or even the subset of the tests. You can specify a filter string in the GTEST_FILTER environment variable or in the --gtest_filter command line option and googletest will only run the tests whose full names (in the form of TestSuiteName.TestName) match the filter. More information about the format of the filter string can be found in Running a Subset of the Tests section. Also googletest supports --gtest_list_tests command line option to print the list of all test cases. It can be useful in your case.