使用googletest框架,我尝试创建一个继承的治具类,以便进行参数化和共享资源测试。
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的一部分,在返回新的TestClass()时有415行
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宏)。如果可以,我该怎么做?
发布于 2017-06-07 10:56:23
这里的问题是TestWithParam<>继承了Test::Test,并且存在一个模棱两可的转换。相反,从WithParamInterface<>继承
https://stackoverflow.com/questions/40474964
复制相似问题