【发布时间】:2019-06-25 09:34:43
【问题描述】:
我正在尝试编写一个执行测试套件级别“设置”操作的测试套件。
我首先尝试编写一个简单的程序来尝试让它工作,但我没有任何运气来调用“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() 从未被调用过。
我一直在阅读 Google 测试文档的 Sharing Resources Between Tests in the Same Suite 部分,但我不知道我做错了什么。
我有什么遗漏吗?
注意:我使用的是 gtest v1.6.0 - 它是我公司 Red Hat RPM 存储库中唯一可用的软件包。
【问题讨论】:
标签: c++ unit-testing automated-tests googletest test-suite