参数化和共享资源测试在googletest
Both parameterized and sharing recources test in googletest
使用googletest框架,我尝试创建一个继承的fixture类,以便进行参数化和共享资源测试。
class FixtDBadminConnShared : public ::testing::Test {
public:
static void SetUpTestCase() {
shared_conn_ = new ::DB::DB_connection();
}
static void TearDownTestCase() {
delete shared_conn_;
}
static ::DB::DB_connection * shared_conn_;
};
::DB::DB_connection * FixtDBadminConnShared::shared_conn_ = nullptr;
class FixtDBadminConnExec :public FixtDBadminConnShared, public ::testing::TestWithParam<string>
{
protected:
using FixtDBadminConnShared::SetUpTestCase;
using FixtDBadminConnShared::TearDownTestCase;
void SetUp() override {
query_ = GetParam();
}
string query_;
};
尝试调用测试:
TEST_P(FixtDBadminConnExec, SelectWithoutParam) {
//do smth
}
INSTANTIATE_TEST_CASE_P(QueriesOrbital0param, FixtDBadminConnExec,
::testing::Values( string{ "SELECT * from my_table;" }));
我得到下一个错误
Error C2594 'return': ambiguous conversions from 'FixtDBadminConnExec_SelectWithoutParam_Test *' to 'testing::Test *' gtest_mytest e:libsgoogletestgoogletestincludegtestinternalgtest-param-util.h 415
这里是gtest-param-util.h的一部分,在上有415行返回new TestClass():
template <class TestClass>
class ParameterizedTestFactory : public TestFactoryBase {
public:
typedef typename TestClass::ParamType ParamType;
explicit ParameterizedTestFactory(ParamType parameter) :
parameter_(parameter) {}
virtual Test* CreateTest() {
TestClass::SetParam(¶meter_);
return new TestClass();
}
private:
const ParamType parameter_;
GTEST_DISALLOW_COPY_AND_ASSIGN_(ParameterizedTestFactory);
};
所以,我猜这个问题也可能是我想同时使用参数化测试(TEST_P宏)和共享资源测试(TEST_F宏)。如果可以,我怎么能做到呢?
这里的问题是TestWithParam<>继承自Test::Test,并且有一个不明确的转换。相反,从WithParamInterface<>
相关文章:
- googletest:测试太大的数据结构
- 禁用自动捕获 Googletest 单元测试中的C++异常
- googletest:测试基类具有纯虚拟方法的派生类时的核心转储
- 使用 googletest 测试嵌入式C++代码时处理外设寄存器的重复符号
- GoogleTest 中的参数化测试无法按预期工作
- cmake googletest不运行测试,没有输出
- C++ / GoogleTest - 如何在链接目录中为每个测试运行安装程序
- C++ / GoogleTest - 如何测试正在测试的类的成员变量
- 使用 googletest 在类型参数化测试中标识使用的基类
- 对单元测试(googletest)和项目/文件夹/文件的混淆
- 在Googletest中循环测试案例
- googletest:死亡测试:单个测试中的多个期望
- 使用 googletest 测试常量行为
- 按类别对 googletest 单元测试进行分组
- GoogleTest参数化测试-可以在参数之间调用SetUp和TearDown
- 类似于GoogleTest的C++单元测试工具
- 如何在Googletest中运行两个不同的测试
- 枚举类的GoogleTest测试错误打印
- 使用googletest测试受保护的成员
- GoogleTest C++-测试夹具