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


Customizing the module's entry point

In this usage variant and in the translation unit containing the definition of BOOST_TEST_MODULE, you need to define the macros BOOST_TEST_NO_MAIN and BOOST_TEST_ALTERNATIVE_INIT_API (their values are irrelevant) prior to including any of the framework's headers. Next, you have to define your custom entry point, and invoke the default test runner unit_test_main manually with the default initialization function init_unit_test as argument.

Example: using custom entry point


#define BOOST_TEST_MODULE custom_main
#include <boost/test/included/unit_test.hpp>
#include <iostream>
namespace utf = boost::unit_test;


void make_use_of(char**)
  std::cout << "Using custom entry point..." << std::endl;

int main(int argc, char* argv[], char* envp[])
  return utf::unit_test_main(init_unit_test, argc, argv);


> custom_main
Using custom entry point...
Running 1 test case...
test.cpp(10): error: in "test1": check false has failed

*** 1 failure is detected in the test module "custom_main"

In the above example, a custom entry point was selected because the test module, in addition to command line arguments, needs to obtain also the information about environment variables.

[Note] Note

The above example also illustrates that it makes sense to define both BOOST_TEST_MODULE and BOOST_TEST_NO_MAIN. This way, no main is generated by the framework, but the name specified by BOOST_TEST_MODULE is assigned to the Master test suite.

[Note] Note

The reason for defining BOOST_TEST_ALTERNATIVE_INIT_API is described here.