-
Notifications
You must be signed in to change notification settings - Fork 1
Parametrized Tests
Parametrized tests are implemented as mix-ins (just a couple of tests you can insert, mix-in, to other test groups). Mix-ins are organized just like normal tests: there is a MIXIN_GROUP and a couple of MIXIN_TESTs within this group.
The new extension is the MIXIN_PARAMS macro, which is used to define the parameter for your parametrized tests (MIXIN_TESTs). Suppose you have a generic interface for your system under test. This interface can be used as parameter for the MIXIN_TESTs
class SUT
{
public:
virtual const char* className() = 0;
};
MIXIN_PARAMS(DemoMixInGroup) // MIXIN_GROUP name
{
SUT* obj;
char* expectedName;
};
The SUT and MIXIN_PARAMS declaration have to be accessible from both, your MIXIN_TEST implementation and the TESTs where you apply the MIXIN_TESTs. So this declaration will typically be in a header file.
Now you can write your actual MIXIN_TESTs.
MIXIN_GROUP(DemoMixInGroup) {};
MIXIN_TEST(DemoMixInGroup, className)
{
const char* className = params.obj->className();
STRCMP_EQUAL( params.expectedName, className );
}
Use the params struct in your test scope to access your MIXIN_PARAMS. The params struct is also available in the setup and teardown functions of the MIXIN_GROUP definition.
Let’s suppose you have different implementations of your system under test interface: ImplA
, ImplB
TEST_GROUP(ImplATestGroup)
{
ImplA objA;
};
To use a mix-in group within your normal test group, you have to specify the parameters for the mix-in tests.
MIXIN_APPLY(ImplATestGroup, DemoMixInGroup, ImplA_test)
{
params->obj = &objA;
params->expectedName = "ImplA";
}
Now all your tests from the DemoMixInGroup will be executed in the ImplATestGroup with a test name of ImplA_test.
see MixInTest.h, MixInTest.cpp
and MixInApplyTest.cpp
in the tests directory.