On 12.07.19 02:50, John Foster via Boost-users wrote:
I am using boost test within a home-grown GUI, and want to access test results (e.g. the failure message and location when a test fails)
The unit_test::test_observer class provides the virtual method:
void assertion_result(boost::unit_test::assertion_result)
However, unit_test::assertion_result is just an enum indicating success or failure. From there, I cannot see how to access further information about the test result.
The framework also provides the class test_tools::assertion_result, which encapsulates an error message, but this only appears to be used for evaluating pre-conditions. (I would have expected this type to be the argument to unit_test::test_observer::assertion_result).
The log output classes appear to provide more information on test results. These are implemented as streams, which makes it non-trivial to extract test result data.
Does anyone know how I can access the information on test results - success/failure, the test code, the location, etc?
Thanks
John
There is the class "results_collector" that is a singleton collecting the status for each test unit, but this does not collect for the messages. The assertion_result that you are mentioning is not only used for evaluating the pre-conditions. It is also used in the file "boost/test/impl/test_tools.ipp" for the "format_report" (from "report_assertion"). The easiest would be to implement your own log formatter (see base "unit_test_log_formatter"). This is how it is done for the junit formatter for instance, which is quite complicated. A simplified version is the HRF/plain logger. The framework let you declare your own logger through the unit_test_log::add_formatter, and if you want attach a stream to each logger. The stream that you are mentioning is because the logger itself does not own the stream on which it is writing the logs to, as I can eg. redirect the XML logs to a file or stderr from the command line. However in your case, you may ignore this stream and write on the location you want. The functions unit_test_log_formatter::log_entry_* should give you enough granularity. Let me know if this works for you, Raffi