Wednesday, May 26, 2010

JUnit reporter for Unitest++

The C++ testing framework Unittest++ includes a XML reporter but it is not directly usable with most continuous integration (CI) servers such as Hudson and TeamCity. I wrote a XML reporter for Unittest++ that uses the same format as JUnit, the reporter will split test suites into different files and they can be directly used by for example the junitreport task in ant or in your CI build. Download the header and cpp files below and add them to your Unittest++ build.

This is how you normally use Unittest++'s built-in XML reporter:
std::ofstream f("test-report.xml");
UnitTest::XmlTestReporter reporter(f);
UnitTest::TestRunner runner(reporter);
return runner.RunTestsIf(UnitTest::Test::GetTestList(), NULL, UnitTest::True(), 0);
Simply replace it with the following,
std::string f = "TESTS-";
UnitTest::JUnitXmlTestReporter reporter(f);
UnitTest::TestRunner runner(reporter);
return runner.RunTestsIf(UnitTest::Test::GetTestList(), NULL, UnitTest::True(), 0);
Note that the JUnit reporter does not take a complete filename because the JUnit format requires that different test suites are split into different files. The output files are named TESTS-suitename.xml.

Download
JUnitXMLTestReporter.h
JUnitXMLTestReporter.cpp

2 comments:

  1. Thanks!! I'm using this with Hudson, and I'm dumping all tests from different executables in one directory, passing the name of the executable to JUnitXmlTestReporter. So files are named 'testA_SuiteName.xml testB_SuiteName.xml' etc. Any way to get hudson to treat testA and testB as packages? Now it just shows package (root), and all tests under it. Would be nice if it would show package testA and package testB..

    ReplyDelete
  2. Hello,
    I found that the file links are broken. Is it possible to restore them?
    thanks a lot!

    ReplyDelete