boost::test observing failures

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

boost::test observing failures

Boost - Users mailing list

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

 

John Foster

cid:image001.png@01D3CC10.659716E0

Associate Director, Quant Analysis

Regulatory Modelling

Credit Risk Analytics and Portfolio

National Australia Bank

 

Level 15, 500 Bourke St, Melbourne VIC 3000

Tel: +61 (0)3 8641 5228

Email:  [hidden email]

 



The information contained in this email communication may be confidential. If you have received this email in error, please notify the sender by return email, delete this email and destroy any copy.

Any advice contained in this email has been prepared without taking into account your objectives, financial situation or needs. Before acting on any advice in this email, National Australia Bank Limited (NAB) recommends that you consider whether it is appropriate for your circumstances. If this email contains reference to any financial products, NAB recommends you consider the Product Disclosure Statement (PDS) or other disclosure document available from NAB, before making any decisions regarding any products.

If this email contains any promotional content that you do not wish to receive, please reply to the original sender and write "Don't email promotional material" in the subject.



_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users
Reply | Threaded
Open this post in threaded view
|

Re: boost::test observing failures

Boost - Users mailing list
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

_______________________________________________
Boost-users mailing list
[hidden email]
https://lists.boost.org/mailman/listinfo.cgi/boost-users