Boost.Test > Components > The Test Tools
Boost Test logo

Boost Test Library: The Test Tools

Examples and tests


Boost Test Library's Test Tools supply a toolbox to ease a creation and a maintenance of test programs and provide a uniform error reporting mechanism. The toolbox supplied in a form of macro and function declarations. While the functions can be called directly, the usual way to use Test Tools is via convenience macros. All macros arguments are calculated once, so it's safe to pass complex expressions in their place. All macros provide an error location: a file name and a line number. Boost Test Library's Test Tools are intended for test code rather than library or production code, where throwing exceptions, using assert(), boost::concept_check or BOOST_STATIC_ASSERT() may be more suitable ways to detect and report errors. To use the Test Tools you need to link with either the Test Execution Monitor or the Unit Test Framework. For list of all supplied Test Tools and usage examples see the reference.

Among many tools in supplied toolbox, there is the BOOST_CHECK_CLOSE tool that perform floating point comparison of values. See floating point comparison page for detailed description of used algorithms.

In addition to toolbox, the Test Tools also contains separate ostream_test_stream tool. This is class designed to significantly simplify correctness testing of the ostream based output procedures. For detailed description of it's interface and usage see the ostream_test_stream page.

Most of test tools direct values of their arguments to the output stream in some form of log statement. If arguments type does not support operator<<(...) interface you will get a compilation error. You could either implement above interface or prohibit Test tools from logging argument values for specified type. To do so use following statement on file level before first test case including statements failing to comply:


Even though supplied test tools cover wide range of possible checks and provide detailed report on cause of error in some cases you may want to implement and use custom predicate that perform complex check and produce intelligent report on failure. To satisfy this need test tools implements custom predicate support.


The Test Tools are implemented in three modules: two header files and one source file.


contains definition for the convenience macros, some template based Test Tools implementation functions and class ostream_test_stream.


contains implementation for the floating point comparison algorithms, used by BOOST_CHECK_CLOSE tool. They also could be used directly.


contains definition for the most Test Tools implementation functions and class ostream_test_stream implementation.

Since this component is not intended to be used standalone, there are no special compilation instruction for it.

Examples and Tests