Can I get log output only for power supply test failures

I have some registration in my application (this happens to be log4cxx, but I am flexible about this) and I have some unit tests using the boost unit test platform. When my unit tests run, I get a lot of log output, both with passing and failing tests (not only for running statements, but also for my own debugging code in the application code). I would like to get a unit test structure to discard the logs during the tests that pass, and output the logs from the tests that fail (I began to appreciate this behavior when using python / nose).

Is there a standard way to do this with unit test formatting? If not, is there any start to checking / completing the test interceptors that I could use to buffer my logs and conditionally output them to implement this behavior myself?

+5
source share
2 answers

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).

0
source

According to the Boost.Test Documentation, run the test executable using --log_level=error . This will only catch failed test cases.

I checked that it works with BOOST_CHECK(false) , otherwise a properly working project with several thousand tests.

Working with --log_level=all gives the result of all statements. I checked this by referring to wc -l that the number of lines in the log is exactly the same as the number of statements in the tests (the number of which is also reported --report_level=detailed ). Of course, you could also grep write the log for error or failed strings.

-1
source

Source: https://habr.com/ru/post/1485236/


All Articles