Another framework for unit tests with C++
is Boost.Test. There are several ways to
forward the messages to the logging host. The first approach was to
create a bridge to the std::stream
object used by
Boost.
l4snd::ostream_Appender app(new l4snd::FileAppender(new l4snd::SimpleFormatter("appname"), "boostfile.txt")); unit_test_log_t::instance().set_stream(app);
But this would have required modifications within log4sendpp to create logging data on the fly into the stream. And messages from Boost are spread over several callbacks which have to be collected and put together in the end. For these reasons the calls are sent directly to log4sendpp as usual. The only things which have to be done are setting up some callbacks:
using ::boost::unit_test; unit_test_main( &init_unit_test, argc, argv ); unit_test_log_t::instance().set_threshold_level( log_successful_tests ); unit_test_log_t::instance().set_formatter( new l4snd::BoostListener ); results_reporter::set_format( new l4snd::BoostReporter );
See log4sendpp/tests/log4sendpp_boost.cpp
for the main part
of the according test files.
Location information from Boost.Test come with different logging levels depending on the importance of the parts.