Search code examples
c++googletest

Disable whole test case in gtest


How can one disable a complete test case in gtest? (all the tests in a test case, not just individual tests)

The formatting proposed in the gtest doc is to organise the tests in the following fashion:

class1test.cpp:

Test(Class1Test, TestA)
{
    ...
}

Test(Class1Test, TestB)
{
    ...
}

...

class2test.cpp:

Test(Class2Test, TestA)
{
    ...
}

Test(Class2Test, TestB)
{
    ...
}

....

class3test.cpp

and so on...

I know that adding the prefix DISABLED_ to a test will prevent it from running (ex: Test(Class1Test, DISABLED_TestB))

But what if I want to disable all the tests in the test case Class1Test?

This post GoogleTest: How to skip a test? suggest to use gtest filters, but this seems a complicated solution for what I want to do. It gtest filters are indeed the only solution, where should I write a filter that disables a test case?


Solution

  • Running tests with --gtest_filter=-Class1Test.* should skip all tests in Class1Test test case. This does not seem much complicated.