Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>With Boost 1.44.0 (and maybe later versions) you need the following code to create a global fixture which redirects the output of the test program to a file named after the master testsuite in which the test is included (see <a href="http://www.boost.org/doc/libs/1_44_0/libs/test/doc/html/utf/user-guide/test-output/log-ct-config.html" rel="nofollow noreferrer">Boost Documentation</a>)</p> <pre><code>#include &lt;boost/test/unit_test.hpp&gt; #include &lt;string&gt; #include &lt;fstream&gt; struct LogToFile { LogToFile() { std::string logFileName(boost::unit_test::framework::master_test_suite().p_name); logFileName.append(".xml"); logFile.open(logFileName.c_str()); boost::unit_test::unit_test_log.set_stream(logFile); } ~LogToFile() { boost::unit_test::unit_test_log.test_finish(); logFile.close(); boost::unit_test::unit_test_log.set_stream(std::cout); } std::ofstream logFile; }; BOOST_GLOBAL_FIXTURE(LogToFile); </code></pre> <p>In this example <code>logFile</code> is not a static member like in the answer provided by <a href="https://stackoverflow.com/questions/3786639/what-is-the-better-way-to-generate-test-report-in-a-file-using-boost-test/3788021#3788021">Steve Townsend</a> because declaring <code>logFile</code> as static member resulted in wrongly generated XML and accessing the fixture struct is not thread-safe this way.</p> <p><strike>However, there seems to be a bug in Boost 1.44.0 which also results in incorrect XML output getting generated if <code>logFile</code> is not a static member of the fixture struct (probably the same bug I mentioned before). To fix this the line <code>logFile &lt;&lt; "&lt;/TestLog&gt;" &lt;&lt; std::flush;</code> is needed before closing the filestream in the destructor to generate valid XML.</strike><br> Thanks to @Wracky (comment below) I replaced the line <code>logFile &lt;&lt; "&lt;/TestLog&gt;" &lt;&lt; std::flush;</code> with <code>boost::unit_test::unit_test_log.test_finish();</code> which is a much cleaner solution than writing the tag manually.</p> <p><strong>NOTE:</strong> the tests are run with the following parameters: <code>--output_format=XML --log_level=all --report_level=no</code>. This enables the usage of the resulting XML files with the <a href="https://wiki.jenkins-ci.org/display/JENKINS/xUnit+Plugin" rel="nofollow noreferrer">xUnit plugin</a> for the <a href="http://jenkins-ci.org/" rel="nofollow noreferrer">continuous integration server Jenkins</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload