Boost C++ Libraries

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

PrevUpHomeNext

Writing unit tests

Assertion severity level
BOOST_TEST: universal and general purpose assertions
Reported information
Extended comparisons support
Floating point comparison
Enabling tolerance for user-defined types
Tolerance-based comparisons
Theory behind floating point comparisons
Strings and C-strings comparison
Collections comparison
Bitwise comparison
Exception correctness
Time-out for test cases
Expected failures specification
Custom predicate support
Output streams testing tool
BOOST_TEST: details on expressions
Debugging the assertions
Summary of the API for writing tests

Once a test case has been declared, the body of this test should be written. A test case is a sequence of operations in which assertions are inserted. Those assertions evaluate statements that implement the expectation being validated, and report failures and/or informations in a uniform manner, depending on the log level.

The Unit Test Framework's supplies a toolbox of assertions to ease the creation and maintenance of test cases and provide a uniform error reporting mechanism. The toolbox supplied is in most part in a form of macro declarations. An (almost) unique interface to all of them implemented by the macro BOOST_TEST.

[Note] Note

All macros arguments are calculated once, so it's safe to pass complex expressions in their place.

All tools automatically supply an error location: a file name and a line number, which can also be overridden.

[Caution] Caution

The testing tools are intended for unit 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.

For a list of all supplied testing tools and usage examples, see the summary or the reference.


PrevUpHomeNext