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
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 of int
s and the other of string
s, then with just a single test fixture, creates tests for every combination of available values in the 2 vector
s:
#include
#include
#include
#include
#include "gtest/gtest.h"
std::vector ints;
std::vector strings;
class CombinationsTest :
public ::testing::TestWithParam> {};
TEST_P(CombinationsTest, Basic) {
std::cout << "int: " << std::get<0>(GetParam())
<< " string: \"" << std::get<1>(GetParam())
<< "\"\n";
}
INSTANTIATE_TEST_CASE_P(AllCombinations,
CombinationsTest,
::testing::Combine(::testing::ValuesIn(ints),
::testing::ValuesIn(strings)));
int main(int argc, char **argv) {
for (int i = 0; i < 10; ++i) {
ints.push_back(i * 100);
strings.push_back(std::string("String ") + static_cast(i + 65));
}
testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}