
To output to files, I use set_stream. I found it made things easier to have my own version of Boost.Test's "main" function, like this:
// based on: "main" in
int my_unit_test_entrypoint() { using namespace ::boost::unit_test; int ret = boost::exit_exception_failure; try { char * argv[] = { /*add cmdline options here*/ }; // see above int argc = sizeof( argv ) / sizeof( char * ); framework::init( argc, argv );
std::ofstream logStream( "c:\\log.xml" ); unit_test_log.set_stream( logStream );
framework::run();
std::ofstream reportStream( "c:\\report.xml" ); results_reporter::set_stream( reportStream );
results_reporter::make_report();
if ( runtime_config::no_result_code() ) { ret = boost::exit_success; } else { test_unit_id id = framework::master_test_suite().p_id; ret = results_collector.results( id ).result_code(); } } catch( std::logic_error const & ex ) { /*add error reporting here*/ } catch( ... ) { /*add error reporting here*/ } return ret; }
You don't really need to rewrite main to implement redirection. There are several ways to do this. One of simplest id to use global fixture: std::ofstream logStream; std::ofstream reportStream; struct output_setup { output_setup() { logStream.open( "c:\\log.xml" ); unit_test_log.set_stream( logStream ); reportStream.open( "c:\\report.xml" ); results_reporter::set_stream( reportStream ); } }; BOOST_GLOBAL_FIXTURE( output_setup ); Gennadiy