代码之家  ›  专栏  ›  技术社区  ›  tjwrona1992

谷歌测试-使用“SetUpTestSuite”似乎不起作用

  •  1
  • tjwrona1992  · 技术社区  · 7 年前

    我试图先编写一个简单的程序来尝试让它工作,但是我没有任何机会调用“SetUpTestSuite”方法。

    #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();
    }
    

    当我运行此命令时,我得到:

    [==========] 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.
    

    出于某种原因 SetUpTestSuite() 从来没有人打过电话。


    我一直在通读报纸 Sharing Resources Between Tests in the Same Suite

    我有什么遗漏吗?


    注意:我使用的是gtest v1.6.0-它是我公司的Red Hat RPM存储库中唯一可用的软件包。

    1 回复  |  直到 7 年前
        1
  •  26
  •   rveerd    7 年前

    文件似乎有误。应该调用这些方法 SetUpTestCase() TearDownTestCase() . 至少在谷歌测试1.8.0中。

        2
  •  4
  •   Mikeal Simburger    7 年前

    更改似乎尚未发布。这些文档似乎是主分支机构的最新版本,而不是发布的版本。