Google 测试,类型化测试,C++

Google test, Typed test, C++

我在对我的结构进行类型化测试时遇到问题运行。

所以考虑在我的 test.cpp 我有一个模板结构

template<typename T>
struct Something {
    T value;

    // Constructors

};

现在我在文档中声明 typedefs

using MyTypes =
    testing::Types<char, unsigned char, short int, unsigned short int, int,
                   unsigned int, long int, unsigned long int, long long int,
                   unsigned long long int, float, double, long double>;

然后我为我的结构创建测试套件和类型化测试。

TYPED_TEST_SUITE(Something,MyTypes);

TYPED_TEST(Something,arithmetics) {
  Something<TypeParam> smth;
  .....
}

但是当我运行这个时,我得到编译错误error: only virtual member functions can be marked 'override' TYPED_TEST(Something,arithmetics) {

我做错了什么???

您不是从 testing::Test 推导 Something

should look像这样:

template<typename T>
class Something : public testing::Test {
public:
    T value;

    // ...
};

然后在 TYPED_TEST 中您不需要创建此 class 的实例,您已经拥有它:

TYPED_TEST(Something, Arithmetics) {
    EXPECT_EQ(this->value, 0);
}