Wire Sysio Wire Sysion 1.0.0
|
Although Catch allows you to group tests together as sections within a test case, it can still be convenient, sometimes, to group them using a more traditional test fixture. Catch fully supports this too. You define the test fixture as a simple structure:
The two test cases here will create uniquely-named derived classes of UniqueTestsFixture and thus can access the getID()
protected method and conn
member variables. This ensures that both the test cases are able to create a DBConnection using the same method (DRY principle) and that any ID's created are unique such that the order that tests are executed does not matter.
Catch2 also provides TEMPLATE_TEST_CASE_METHOD
and TEMPLATE_PRODUCT_TEST_CASE_METHOD
that can be used together with templated fixtures and templated template fixtures to perform tests for multiple different types. Unlike TEST_CASE_METHOD
, TEMPLATE_TEST_CASE_METHOD
and TEMPLATE_PRODUCT_TEST_CASE_METHOD
do require the tag specification to be non-empty, as it is followed by further macro arguments.
Also note that, because of limitations of the C++ preprocessor, if you want to specify a type with multiple template parameters, you need to enclose it in parentheses, e.g. std::map<int, std::string>
needs to be passed as (std::map<int, std::string>)
. In the case of TEMPLATE_PRODUCT_TEST_CASE_METHOD
, if a member of the type list should consist of more than single type, it needs to be enclosed in another pair of parentheses, e.g. (std::map, std::pair)
and ((int, float), (char, double))
.
Example:
While there is an upper limit on the number of types you can specify in single TEMPLATE_TEST_CASE_METHOD
or TEMPLATE_PRODUCT_TEST_CASE_METHOD
, the limit is very high and should not be encountered in practice.