![]() |
Home | Libraries | People | FAQ | More |
If you look at many legacy test modules, big chance is that it's implemented as one big test function that consists of a mixture of check and output statements. Is there anything wrong with it? Yes. There are various disadvantages in single test function approach:
The above points should make it clear that it's preferable to split a test module into smaller units. These units are the test cases, the test suites and the fixtures.
Subjects covered by this section
The Unit Test Framework supports several methods for declaring a test case. Test cases can be implemented using free function like syntax or based on actual free function, function object, that can be defined with or without parameters/data, or as template functions to be run against various types.
The Unit Test Framework provides facilities to group several test cases into test suites. The test suites can be nested, and the set of test suites and test cases defines the test tree, where the leaves are the test cases. Besides hierarchical structure the Unit Test Framework allows you to organize the test tree using logical grouping and dependencies and provides you with controls to utilize the defined test tree organization the way you want (eg. from command line).
It is possible to specify test unit attributes by using decorators. Attributes are used for a fine grained control over various aspects of test module execution, such as logical grouping, dependencies, expected failures, etc.
When several tests shares the same set-up (environment, test data preparation, etc.), the preparation and cleanup code may be factorized in fixtures. In the Unit Test Framework, fixtures can be associated to test cases, test suites or globally to the test module.