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 a snapshot of the master branch, built from commit d5ec80e6c3.

Customizing the module's initialization function

In the static library variant, customizing the main entry point is quite troublesome, because the default test runner compiled into the static library uses the obsolete initialization function signature. This requires you to rebuild the Unit Test Framework static library with the defined symbol BOOST_TEST_ALTERNATIVE_INIT_API. In the Boost root directory you need to invoke command

> b2 --with-test link=static define=BOOST_TEST_ALTERNATIVE_INIT_API install
[Warning] Warning

This alteration of the static library will affect everybody else who is linking against the library. Consider using the obsolete test initialization function, which requires no rebuilding. Alternatively, it may be less intrusive to switch to the shared library usage variant instead.

In one of the source files, you now have to define your custom initialization function with signature:

bool init_unit_test();

The default test runner will use it to initialize the test module. In your source code, you no longer define macro BOOST_TEST_MODULE; instead, you need to define BOOST_TEST_ALTERNATIVE_INIT_API in the main file:

In exactly one file

In all other files

#include <boost/test/unit_test.hpp>

// init func:
bool init_unit_test()
  return true;
#include <boost/test/unit_test.hpp>

// test cases

// test cases

For reporting errors that may occur during the initialization,

An error reported in this function aborts the execution of the test module.

[Note] Note

The reason for defining BOOST_TEST_ALTERNATIVE_INIT_API is described here.