Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 550
tjwrona1992 Avatar asked Jan 31 '19 20:01

tjwrona1992


2 Answers

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

like image 125
rveerd Avatar answered Nov 15 '22 09:11

rveerd


The change does not appear to have been released. The documents appear to be current with the Master branch, not the released version.

like image 4
Mikeal Simburger Avatar answered Nov 15 '22 08:11

Mikeal Simburger