Boost C++ Libraries of the most highly regarded and expertly designed C++ library projects in the world. Herb Sutter and Andrei Alexandrescu, C++ Coding Standards

This is the documentation for an old version of Boost. Click here to view this page for the latest version.

Declaring and organizing tests

Test cases
Test cases without parameters
Data-driven test cases
Declaring and registering test cases with datasets
Operations on dataset
Datasets generators
Template test cases
Parametrized test cases
Test suite
Master Test Suite
Suite-level decorators
Explicit decorator declaration
Fixture models
Test case fixture
Test suite entry/exit fixture
Global fixture
Managing test dependencies
Grouping tests into logical units by labels
Enabling or disabling test unit execution
Adding semantic to a test
Summary of the API for declaring and organizing tests

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, The 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.


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.

Setup/teardown test unit actions

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.