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?
Google Test supports set-up and tear-down on test (test method) level, suite (class) level and also on program level. The later is the one you seam to look for:
https://github.com/google/googletest/blob/master/docs/advanced.md#global-set-up-and-tear-down describes how you can derive and register you own environment-fixture class implementing set-up and tear-down methods, which are called only once during the execution of your test runner.
In short you can do something similar to that:
class SetupEnvironment : public ::testing::Environment
{
public:
virtual ~SetupEnvironment();
void SetUp() override { ... }
void TearDown() override { ... }
};
int main(int argc, char* argv[])
{
testing::AddGlobalTestEnvironment(new SetupEnvironment());
return RUN_ALL_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