Search code examples
c++c++17googletest

How to combine "Values" and "Combine"?


I want to add some special set of values to cartesian product. Something like this:

INSTANTIATE_TEST_SUITE_P(Test, Test, 
    testing::Values(
        testing::Combine(
            testing::Values(1, 2, 3), 
            testing::Values("one", "two", "three")),
        testing::Values(std::make_tuple(12345, "big value"))));

But it's not working. Is there any other working way to do it?


Solution

  • You can do two instantiations:

    INSTANTIATE_TEST_SUITE_P(TestSanity, Test, 
        testing::Combine(
            testing::Values(1, 2, 3), 
            testing::Values("one", "two", "three")));
    
    INSTANTIATE_TEST_SUITE_P(TestSpecial, Test, 
        testing::Values(std::make_tuple(12345, "big value")));
    

    Only Combine() accepts other generators as input, but that would be undesirable. However, the problem can be easily solved by using two separate macro calls, producing two test suites out of your tests. See it online.