gpt4 book ai didi

c++ - Google 测试 - 使用 "SetUpTestSuite"似乎不起作用

转载 作者:可可西里 更新时间:2023-11-01 18:23:16 24 4
gpt4 key购买 nike

我正在尝试编写一个测试套件来执行测试套件级别的“设置”操作。

我试图首先编写一个简单的程序来尝试让它工作,但我没有运气调用“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 Google 测试文档的一部分,但我不知道我做错了什么。

有什么我想念的吗?


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

最佳答案

文档似乎有误。这些方法应称为 SetUpTestCase()TearDownTestCase()。至少在 Google Test 1.8.0 中是这样。

关于c++ - Google 测试 - 使用 "SetUpTestSuite"似乎不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54468799/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com