Search code examples
c++unit-testinggoogletest

Advanced use of googletest's parameterization


I have several questions about googletest framework and its usage:

By fixture in the following questions I mean a class derived from ::testing::Test

  1. As far as I know, I can use fixture along with parameterization feature of gtests. Does this apply to both value-parameterization and type-parameterization?

  2. There are cases when the fixture is irrelevant. Can I use type-parameterization with value-parameterization without fixture? How (example would be nice)?

  3. Pure interest: Can I use fixture together with type- and value-parameterization? (I am quite sure this is a needless complexity)


Solution

  • As far as I know, I can use fixture along with parameterization feature of gtests. Does this apply to both value-parameterization and type-parameterization?

    Yes, both value-parameterized tests and typed tests or type-parameterized tests must be derived from a fixture class. The linked documentation provides examples.

    Can I use type-parameterization with value-parameterization without fixture

    I presume you mean "type-parameterization OR value-parameterization". Anyway, you cannot use either without a fixture class, as per the same documentation.

    Can I use fixture together with type- and value-parameterization?

    Googletest does not expressly support type-and-value-parameterized tests, but you can make a good approximation to it with type-parameterized tests, as I illustrated in a previous answer