There are start of test and end of test hooks that you can use for this purpose. To set up these hooks you need to define a subclass of boost::unit_test::test_observer, create an instance of the class that will persist throughout the entire test (either a static global object or a BOOST_TEST_GLOBAL_FIXTURE), and then pass the class to boost::unit_test::framework::register_observer.
The method to override with a start of test hook is test_unit_start
, and the method to override with an end of test hook is test_unit_finish
. However, these hooks fire both for test suites as well as individual test cases, which may be an issue depending on how the hooks are set up. The test_unit_finish
hook also doesn't explicitly tell you whether a given test actually passed, and there doesn't seem to be one clear and obvious way to get that information. There is a boost::unit_test::results_collector singleton, which has a results() method, and if you pass it the test_unit_id
of the test unit provided to test_unit_finish
, you get a test_results object that has a passed() method. I can't really see a way to get the test_unit_id
that is clearly part of the public API -- you can just directly access the p_id member, but that could always change in a future boost version. You could also manually track whether each test is passing or failing using the assertion_result
, exception_caught
, test_unit_aborted
, and test_unit_timed_out
hooks from the test_observer subclass (assertion_result
indicates a failure of the current test whenever its argument is false and every other hook indicates a failure if it is called at all).
std::cout
orstd::cerr
but this can be a feature request I may consider (see project's github). This would mean that your code is logging to one of those streams. – Gurnard