There is the beginning of the test and the end of the test leads that you can use for this purpose. To set up these traps , you need to define a subclass of boost :: unit_test :: test_observer , create an instance of the class that will be preserved throughout the test (static global object or BOOST_TEST_GLOBAL_FIXTURE ), and then pass the class to boost :: unit_test :: framework :: register_observer .
The override method with the start of the test hook is test_unit_start , and the override method with the end of the test hook is test_unit_finish . However, these hooks are triggered both for test suites and for individual test cases, which can be a problem depending on how the hooks are configured. test_unit_finish also does not explicitly tell you if the given test actually passed, and there does not seem to be one clear and obvious way to get this information. There is a singleton boost :: unit_test :: results_collector that has a results () method, and if you pass it the test_unit_id test block provided by test_unit_finish , you get a test_results object that has a pass () method. I really can't find a way to get test_unit_id which is clearly part of the public API - you can just get direct access to the p_id member, but that can always change in a future improved version. You can also manually track whether each test passes or test_unit_aborted , with test_unit_timed_out hooks assertion_result , exception_caught , test_unit_aborted and test_unit_timed_out from the test_observer subclass ( assertion_result indicates the failure of the current test when its argument is false, and each other is false, and the other called at all).
source share