简体   繁体   中英

Google test, Typed test, C++

I am having trouble running a typed test for my struct.

So consider in my test.cpp I have a template struct

template<typename T>
struct Something {
    T value;

    // Constructors

};

Now I declare typedefs as mention in documentation.

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>;

Then I create the test suite and the typed test for my struct.

TYPED_TEST_SUITE(Something,MyTypes);

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

But when I run this, I get compile error error: only virtual member functions can be marked 'override' TYPED_TEST(Something,arithmetics) {

What am I doing wrong???

You're not deriving Something from testing::Test .

It should look like this:

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

    // ...
};

Then inside TYPED_TEST you don't need to create an instance of this class, you already have it:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM