I'm currently trying to generate some post coding UT for a module. The module classifies input data to a DB, if a match is found, a proper value is returned.
After building a table with all possible input scenarios and their expected results, I discovered that I got over 50 tests to create. As all tests are basically the same, except the test name and the inputs, some kind of template seemed to fit here, reducing code mess.
What I originally imagined, was either a macro that creates such a template and expands to the tests with input data and the expected result OR using a structure representing the scenario table with some help from a macro to wrap it up. (I guess a C++ template is also adequate here).
However, I'm not sure this is a correct path to take and would like to know if anyone can give some recommendations of how to tackle it. There is also the question of how it fits a TDD approach..
Here is the idea using CppUTest:
#define GEN_TEST_MOD_CLASSIFIER(GROUP_NAME, TEST_NAME, PRIORITY, isCOMPRESS, isX, EXPECTING) \
TEST(GROUP_NAME, TEST_NAME) \
{ \
int hit; \
setupDB(PRIORITY, isCOMPRESS, isX); \
hit = func(PRIORITY, isCOMPRESS, isX); \
CHECK_EQUAL(EXPECTING, hit); \
}
Usage example:
GEN_TEST_MOD_CLASSIFIER(Classifier_Tests, LowPriority_NoCompress_NoX__HIT, PRIO_LOW, NOT_COMPRESS, NO_X, HIT_DB)