Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Test module's entry point

Typically, every C++ program contains exactly one definition of function main: the program's entry point. When using the Unit Test Framework you do not have to define one. Function main will be generated for you by the framework. The only thing you are required to do in case your program consists of more than one translation unit (cpp file) is to indicate to the framework in which of the files it is supposed to generate function main. You do it by defining macro BOOST_TEST_MODULE before the inclusion of any of the framework files. The value of this macro is used as a name of the test module as well as the master test suite.

The reason for defining function main for you is twofold:

  1. This allows the Unit Test Framework to perform some custom test module initialization.
  2. This prevents you defining main, and accidentally forgetting to run all the test (in which case running the program would incorrectly indicate a clean run).

By default, the test module's entry point is defined with signature:

int main(int argc, char* argv[]);

It calls test module initialization function, then calls the test module runner and forwards its return value to environment.

The default entry point is sufficient in most of the cases. Occasionally, a need may arise to declare an entry point with a different name or signature. For overriding the definition of the default test module's entry point:


PrevUpHomeNext