inheritance and TestWithParam

814 views
Skip to first unread message

Joey

unread,
Aug 19, 2010, 8:13:39 PM8/19/10
to Google C++ Testing Framework
Most of my test cases are now data-driven with TestWithParam. I use an
array-of-structures where each structure describes one interesting
combination of values. Like it says in the FAQ this approach has lots
of advantages over using subroutines.

The catch is that I end up testing one logical grouping need several
test fixtures that vary only in parameter datatype like:

class FixtureA : public ::testing::TestWithParam<struct_A_t>;
class FixtureB : public ::testing::TestWithParam<struct_B_t>;
class FixtureWithoutParametersC : public ::testing::Test;

Where A might iterate across several baudrates, while B is going to
vary in some different way, and C contains tests that need no
parameter. But they still have some pieces in common.
With ::testing::Test this is easy to express because you can can use
one fixture or subclass and create several fixtures.

What about for TestWithParam? For now I just do as above which results
in some code duplication and pushes me toward using more globals.
Multiple inheritance might work instead. What do you think?

Vlad Losev

unread,
Aug 20, 2010, 7:28:38 PM8/20/10
to Google C++ Testing Framework
Hi Joey,
My advice would be to factor out all the common stuff into a separate class and then instantiate and access it in your fixture classes. But you should be able to do it with mixins, as well. It can also be done using a templated base class, although that makes your code - and compiler errors it produces - harder to understand.

- Vlad
Reply all
Reply to author
Forward
0 new messages