Search code examples
c++unit-testingautomated-testsgoogletesttest-suite

Google Test - Using "SetUpTestSuite" doesn't seem to work


I'm trying to write a test suite that performs a test-suite level "Set Up" operation.

I attempted to write a simple program first to try and get it working but I am not having any luck getting the "SetUpTestSuite" method to be called.

#include <gtest/gtest.h>
#include <iostream>

class MyTest : public ::testing::Test
{
protected:
    static void SetUpTestSuite() {
        std::cerr << "TestSuiteSetup" << std::endl;
    }

    static void TearDownTestSuite() {

    }
};

TEST_F(MyTest, Case1) {
    std::cerr << "TESTING" << std::endl;
}

int main(int argc, char* argv[])
{
    ::testing::InitGoogleTest(&argc, argv);
    return RUN_ALL_TESTS();
}

When I run this I get:

[==========] Running 1 tests from 1 test cases.
[----------] Global test environment set-up.

[----------] 1 test from MyTest
[ RUN      ] MyTest.Case1
TESTING
[       OK ] MyTest.Case1 (0 ms)
[----------] 1 test from MyTest (0 ms total)

[----------] Global test environment tear-down
[==========] 1 tests from 1 test cases ran. (0 ms total)
[  PASSED  ] 1 tests.

For some reason SetUpTestSuite() is never called.


I have been reading through the Sharing Resources Between Tests in the Same Suite section of the Google Test documentation but I can't figure out what I am doing wrong.

Is there something I am missing?


Note: I am using gtest v1.6.0 - it is the only package that was available from my companies Red Hat RPM repository.


Solution

  • The documentation appears to be wrong. These methods should be called SetUpTestCase() and TearDownTestCase(). At least in Google Test 1.8.0.