boost unit tests with xUnit Plugin in Jenkins do not work
The error is is because there is no output file generated by boost::test
. The test script need to be invoked with the correct options:
unit_test --report_level=detailed --report_format=xml 2> xunit.xml
Unfortunately the XML output file produced by boost::test is not in the correct format (see: SO Converting boost::test logs & Boost Users Help with XUnit plugin )
The JUnit plugin expects XML test output to be in the following format:
<testsuites> <testsuite time="0.0000" timestamp="0.000" errors="0" failures="0" tests="13" hostname="localhost" name="my_test_suite"> <testcase id="65536" class="test" name="test_case_1" time="0.0000" /> <testcase id="65537" class="test" name="test_case_2" time="0.0000" /> <testcase id="65538" class="test" name="test_case_3" time="0.0000" /> </testsuite></testsuites>
There are a couple of ways to resolve this such as:
- Converting the XML output by
boost::test
- Directly customising the output of
boost::test
so that the correct format is produced.
I opted for option 2 - ss you are not a 'C/C++' programmer you could get the author of the test suites you are trying to run to follow this approach, the steps below should help get them started:
- Create a test visitor for post processing the results of the test run.
- Create a BOOST_GLOBAL_FIXTURE class that walks through the test results in its destructor to output the test results in the correct format.
- Instantiate the fixture class in the main test module.
i.e.:
struct JUnitVisitor : public boost::unit_test::test_tree_visitor{ void visit( boost::unit_test::test_case const& tc ) { // output <testcase> xml in JUnit format } bool test_suite_start( boost::unit_test::test_suite const& ts ) { // output <testuite> xml in JUnit format } void test_suite_finish( boost::unit_test::test_suite const& ts ) { // output </testuite> xml in JUnit format }};struct MyJUnitOpFixture{ MyJUnitOpFixture() {} ~MyJUnitOpFixture() { // open results file /// output <testsuites> start tag // use a visitor to walk the test results tree JUnitVisitor visitor ( out ); boost::unit_test::traverse_test_tree( boost::unit_test::framework::master_test_suite(), visitor ); /// output </testsuites> end tag }}
Then the global fixture is instantiated in the main test file by adding:
BOOST_GLOBAL_FIXTURE( MyJUnitOpFixture );
In my case xUnit does not like format of Boost Test's "--report_format=XML"
but it DOES take "--log_format=XML --log_sink=test.xml"