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

Customizing the module's initialization function
PrevUpHomeNext

In this usage variant, you do not define macro BOOST_TEST_MODULE and instead provide the definition of function init_unit_test. This is going to be the custom initialization function. The default test runner will use it to initialize the test module.

Example: using custom initialization function

Code

#define BOOST_TEST_ALTERNATIVE_INIT_API
#include <boost/test/included/unit_test.hpp>
#include <iostream>

BOOST_AUTO_TEST_CASE(test1)
{
  BOOST_TEST(false);
}

bool init_unit_test()
{
  std::cout << "using custom init" << std::endl;
  return true;
}

Output

> custom_init
using custom init
Running 1 test case...
test.cpp(7): error: in "test1": check false has failed

*** 1 failure is detected in the test module "Master Test Suite"
[Note] Note

Because we overwrote the default initialization function, it does no longer assign any name to the master test suite. Therefore the default name ("Master Test Suite") is used.

[Note] Note

The reason for defining BOOST_TEST_ALTERNATIVE_INIT_API is described here.


PrevUpHomeNext