使用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:\libs\googletest\googletest\include\gtest\internal\gtest-param-util.h 415
以下是 gtest-param-util.h 的一部分,上的415行返回新的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宏)。我怎么能这样做?如果可以的话?
答案 0 :(得分:3)
你的问题是TestWithParam&lt;&gt;继承自testing :: Test并且存在模糊的转换。相反,继承自WithParamInterface&lt;&gt;