...one of the most highly
regarded and expertly designed C++ library projects in the
world.
— Herb Sutter and Andrei
Alexandrescu, C++
Coding Standards
If you want to redirect the test log output stream into something different
from the logger default output stream (usually std::cout
,
std::cerr
or a file), use the following interface:
boost::unit_test::unit_test_log.set_stream( std::ostream& );
or for a particular log format:
boost::unit_test::unit_test_log.set_stream( boost::unit_test::output_format, std::ostream& );
Tip | |
---|---|
See |
You can reset the output stream at any time both during the test module initialization and from within test cases. There are no limitations on number of output stream resets neither.
Warning | |
---|---|
If you redirect test log output stream from global fixture setup, you
are required to reset it back to |
Code |
---|
#define BOOST_TEST_MODULE example #include <boost/test/included/unit_test.hpp> #include <fstream> struct MyConfig { MyConfig() : test_log( "example.log" ) { boost::unit_test::unit_test_log.set_stream( test_log ); } ~MyConfig() { boost::unit_test::unit_test_log.set_stream( std::cout ); } std::ofstream test_log; }; BOOST_TEST_GLOBAL_CONFIGURATION( MyConfig ); BOOST_AUTO_TEST_CASE( test_case ) { BOOST_TEST( false ); } |
Output |
---|
> example *** 1 failures is detected in test suite "example" > cat example.log Running 1 test case... test.cpp(26): error in "test_case": check false failed |