C++ – gtest equivalent for fixture-level setup/teardown

cgoogletesttesting

So, I know there's "literally" fixtures for gtest, but the constructor/destructor and setup/teardown functions will execute after each test rather than after the entire set of tests in the fixture.

I can think of ways of hacking around this, but is there some built-in support that I'm not finding?

Best Answer

You can define static methods SetUpTestSuite and TearDownTestSuite in your test fixture class:

struct MyTest: ::testing::Test {
    static void SetUpTestSuite() {
        
    }

    static void TearDownTestSuite() {
        
    }
};

More information on that is in the Googletest wiki.

Be careful about the spelling of these static method names.

Related Topic