OK, my test_observer_fixture with overloads is ready:
class test_observer_fixture { struct test_observer : public utf::test_observer { virtual void test_unit_aborted(utf::test_unit const& tu) override; virtual void assertion_result(utf::assertion_result result) override; // are the others required for my use case? };
test_observer observer;
public: test_observer_fixture(); ~test_observer_fixture();
public: void setup(); void teardown(); };
and get called by my BOOST_DATA_TEST_CASE. What is the prefered way to use this Fixture to save the test result in case of failure/abort?
BOOST_DATA_TEST_CASE( wave, utf_data::make_delayedtestsuite::dataset_loader( "test_case/wave" ), input, expected, orig_file_name) { ... auto [parse_ok, parse_result] = parse(input, parser, test_case_name);
BOOST_REQUIRE(parse_ok);
BOOST_TEST(parse_result == expected, btt::per_element());
??? my_diagnostic_saving .... (orig_file_name, input, parse_result); ); }
Thanks, Olaf
Sorry for the late answer,
In the teardown, you may check if the current test had failures. You can do so by accessing the global singleton "results_collector". If "tc" is the current test case (that you can get with "current_test_case"):
test_results const& tr = results_collector.results( tc.p_id );
will give you the result.
If the fixture should be applied to each of the test case inside your suite, you can install it like this:
https://www.boost.org/doc/libs/1_67_0/libs/test/doc/html/boost_test/tests_or...
Accessing via the test result will let you check if this is a failure or an abort: the BOOST_TEST_REQUIRE (BOOST_REQUIRE is deprecated) will fire an abort if I remember well. Using this way to install the fixture will also let you access the instance of the fixture directly (see examples in the documentation).
Since my global testobserver works for all events which may interested
even in the future (e.g exceptions), I have problems to apply them in my
use case.
I've added a member function to my testobserer fixture
void test_obserer_fixture::failure_diagnostic(std::string const&, ...)
which I can activate on failed tests using the events I've got from
utf::observer::assertion_result()
Now, in file test_main.cpp I have:
-----------------------------------------
#define BOOST_TEST_MODULE "Test Suite"
#include