...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
boost::unit_test::test_observer — Generic test observer interface.
// In header: <boost/test/tree/observer.hpp> class test_observer { public: // construct/copy/destruct ~test_observer(); // public member functions virtual void test_start(counter_t); virtual void test_finish(); virtual void test_aborted(); virtual void test_unit_start(test_unit const &); virtual void test_unit_finish(test_unit const &, unsigned); virtual void test_unit_skipped(test_unit const &, const_string); virtual void test_unit_skipped(test_unit const &); virtual void test_unit_aborted(test_unit const &); virtual void assertion_result(unit_test::assertion_result); virtual void exception_caught(execution_exception const &); virtual int priority(); // protected member functions virtual void assertion_result(bool); };
This interface is used by observers in order to receive notifications from the Boost.Test framework on the current execution state.
Several observers can be running at the same time, and it is not unusual to have interactions among them. The test_observer::priority member function allows the specification of a particular order among them (lowest priority executed first, except specified otherwise).
test_observer
public member functionsvirtual void test_start(counter_t);Called before the framework starts executing the test cases.
virtual void test_finish();Called after the framework ends executing the test cases.
Note | |
---|---|
The call is made with a reversed priority order. |
virtual void test_aborted();Called when a critical error is detected.
The critical errors are mainly the signals sent by the system and caught by the Boost.Test framework. Since the running binary may be in incoherent/instable state, the test execution is aborted and all remaining tests are discarded.
Note | |
---|---|
may be called before test_observer::test_unit_finish() |
virtual void test_unit_start(test_unit const &);Called before the framework starts executing a test unit.
virtual void test_unit_finish(test_unit const &, unsigned long);Called at each end of a test unit.
virtual void test_unit_skipped(test_unit const & tu, const_string);
virtual void test_unit_skipped(test_unit const &);backward compatibility
virtual void test_unit_aborted(test_unit const &);Called when a test unit indicates a fatal error.
A fatal error happens when
a strong assertion (with REQUIRE
) fails, which indicates that the test case cannot continue
an unexpected exception is caught by the Boost.Test framework
virtual void assertion_result(unit_test::assertion_result ar);
virtual void exception_caught(execution_exception const &);Called when an exception is intercepted.
In case an exception is intercepted, this call happens before the call to test_unit_aborted in order to log additional data about the exception.
virtual int priority();The priority indicates the order at which this observer is initialized and tore down in the UTF framework. The order is lowest to highest priority.