【发布时间】:2015-06-15 09:03:34
【问题描述】:
我有一个 gtest 参数化类,我想在每个参数之间调用一些 SetUp 和 TearDown。我知道 googletest 提供在每个测试用例之前的 SetUp 和在所有测试用例之前的 SetUpTestCase。
我有这样的事情:
class MyParameterizedTest: public TestWithParam<MyParams>
{
public:
MyParameterizedTest() {}
void SetUp()
{
//called before every test case
}
void TearDown()
{
//called after every test case
}
static void SetUpTestCase()
{
//called at the begining of framework and before all test cases
}
static void TearDownTestCase()
{
//called at the end of the framework and after all test cases
}
//Wishing for something like:
// void SetUpParameter()
{
//called before start of parameter
}
};
INSTANTIATE_TEST_CASE_P(RegistrationTest, InterfaceTest, ValuesIn(AllTheValues::GetAllMyParams()));
有什么想法可以使这项工作有效吗?也许是一种查看特定参数的最后一个测试用例何时运行的方法?还是我必须为每个单独的参数实例化一个测试用例?
【问题讨论】:
-
您确定您的代码不起作用吗?每个类的静态函数是独立的,而不是每个类模板。
-
澄清一下:你说的是type-parametrized tests。
-
是类型参数化测试。很好的澄清。我不确定测试类的底层模板是如何工作的,但我确信静态 SetUpTestCase 和 TearDownTestCase 只为我的全套测试用例调用一次
标签: c++ unit-testing googletest parameterized-unit-test