Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

Need help on XML / Hudson

Help
Mawg
2009-03-26
2013-04-22
  • Mawg
    Mawg
    2009-03-26

    I am installing and configuring Hudson (https://hudson.dev.java.net/) as a continuous build server.

    After much googling about using it with C++ (it was originally designed for Java), I found several pages which all agreed that CppUnit's XML output can be transformed to look like Junit's and then fed to Hudson.

    Unfortunately, every web page I find which claims to show how to generate XML output does not compile. 

    Can anyone give a very simple example of how to redirect CppUnit output to XML, or point me to a URL which you are *suer* actually has compilable code?

    Thanks in advance for any help. I am using v 1.12.1

     
    • "Can anyone give a very simple example of how to redirect CppUnit output to XML, or point me to a URL which you are *suer* actually has compilable code? "

      To redirect the XML output to a file:

      ...
      CppUnit::TextUi::TestRunner runner;
      std::ofstream fs("Result.xml");
      CppUnit::XmlOutputter* outputter =
      new CppUnit::XmlOutputter(&runner.result(), fs);
      runner.setOutputter(outputter);
      CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("Test");
      runner.addTest( registry.makeTest());
      bool wasSucessful = runner.run();
      ...

      To redirect the XML output to the console use
      CppUnit::XmlOutputter* outputter =
      new CppUnit::XmlOutputter(&runner.result(), std::cerr);

        I'm using the 1.12.0 version. Let me know if this was helpful.

      Cheers,

       
    • Mawg
      Mawg
      2009-03-27

      I love you and want to have your babies!!

      That works like a charm on 1.12.1. Thank you so very much. After so many "solutions" which do not compile, that was very, very welcome.

      I know where to come for help in future. Watch out :-)

      One minor point. I had to change your

      CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("Test");

      to

      CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry();   // removed "Test"

      before my test would run. I don't understand why, but never mind because it works!

      <?xml version="1.0" encoding='ISO-8859-1' standalone='yes' ?>
      <TestRun>
        <FailedTests></FailedTests>
        <SuccessfulTests>
          <Test id="1">
            <Name>BaseClassTestSuite::testMultipleObjectCreation</Name>
          </Test>
          <Test id="2">
            <Name>BaseClassTestSuite::testMultipleObjectDeletion</Name>
          </Test>
          <Test id="3">
            <Name>BaseClassTestSuite::testObjectManagerCreation</Name>
          </Test>
          <Test id="4">
            <Name>BaseClassTestSuite::testObjectMagerDeletion</Name>
          </Test>
        </SuccessfulTests>
        <Statistics>
          <Tests>4</Tests>
          <FailuresTotal>0</FailuresTotal>
          <Errors>0</Errors>
          <Failures>0</Failures>
        </Statistics>
      </TestRun>

       
    • Glad I could be of help :)

      About that CppUnit::TestFactoryRegistry &registry = CppUnit::TestFactoryRegistry::getRegistry("Test") line:

      I forgot I used a named registry (the name is of the registry is "Test") and you just use the unamed registry. ( CPPUNIT_TEST_SUITE_REGISTRATION() vs CPPUNIT_TEST_SUITE_NAMED_REGISTRATION()  )

      Cheers,