I have a unit test that I need to run for 200 possible combinations of data. (The production implementation has the data to be tested in configuration files. I know how to mock these values). I prefer nit writing separate test case for each combination and to use some way of looping through the data. Is there some such direct way using Google test for C++?
Thanks, Karthick
Use an array of structs (called, say,
Combination
) to hold your test data, and loop though each entry in a single test. Check each combination usingEXPECT_EQ
instead ofASSERT_EQ
so that the test isn't aborted and you can continue checking other combinations.Overload
operator<<
for aCombination
so that you can output it to anostream
:Overload
operator==
for aCombination
so that you can easily compare two combinations for equality:And the unit test could look something like this:
You can make use of gtest's Value-parameterized tests for this.
Using this in conjunction with the
Combine(g1, g2, ..., gN)
generator sounds like your best bet.The following example populates 2
vector
s, one ofint
s and the other ofstring
s, then with just a single test fixture, creates tests for every combination of available values in the 2vector
s: