I am trying to start unit testing. I am looking at a few C++ frameworks and want to try Boost.Test. The documentation seems very thorough, and it\'s a bit overwhelming, espe
In your test_foo.cpp, the macros add test suites and test cases in
to a global list: master_testsuite, which is the root of all test
nodes. You just need to compile all the test files like
test_foo.cpp, test_boo.cpp and a runner, then link them all into on
executable.
The function unit_test_main is used to run the tests in master_testsuite.
boost::unit_test::unit_test_main(
&init_unit_test,
argc,
argv
)
Based on the macro you defined before including
, Boost.Test may already generate the main
function for you.[1] The generated main simply invoked
unit_test_main with argc and argv in main. It's recommended to
use unit_test_main because it can process some console arguments,
like run test by name.
The first argument of unit_test_main is a hook. Depending on
BOOST_TEST_ALTERNATIVE_INIT_API, it has different definition.
#ifdef BOOST_TEST_ALTERNATIVE_INIT_API
typedef bool (*init_unit_test_func)();
#else
typedef test_suite* (*init_unit_test_func)( int, char* [] );
#endif
You can customize the master_testsuite in the hook. In the second
form, the returned value is the new master testsuite.
[1] if BOOST_TEST_MAIN and BOOST_TEST_MAIN are defined, but
BOOST_TEST_NO_MAIN is not.