Menu

jUnitReport equivalent for XmlOutputter?

Help
2005-01-02
2013-04-22
  • Steve Kelem

    Steve Kelem - 2005-01-02

    I'm just starting to use CppUnit, coming from the Java world.

    I am now able to write xml output for tests.

    How do I gather all the xml files together and create the hierarchy of web pages, as I could in Ant's junitreport task?  Do I need to run Ant to run junitreport?

    Thanks,
    Steve

     
    • Edwin Fine

      Edwin Fine - 2005-01-26

      I once wrote a suite similar to CppUnit that produced XML output that was Junit-compatible, so it is certainly possible.

      However, I will assume, based on the deafening silence in response to your question and other similar questions, that the XML output produced by CppUnit is not directly usable with the JUnit backends. I hope I am wrong.

      If my assumption is correct, I see three options:
      (a) Add this feature to CppUnit yourself, or
      (b) Transform the XML that is produced into a compatible format, if that is even possible, or
      (c) use a different unit test framework.

      There is always the option to write your own framework, too, but that seems extreme.

       
    • tca

      tca - 2005-04-26

      I use a perl script to run my tests - each test is a stand alone executable which reports in XML format.  From this I my perl script gathers all the xml files and dumps them into a repository.  I then use simple xslt to display the reporting.

      I could not find anything similar to what you describe from ant.

       
    • Mark Ivey

      Mark Ivey - 2005-04-27

      I use this XSL to convert the CppUnit output.  No guarantees that it is correct, but it is at least good enough to make CruiseControl happy.

      <?xml version="1.0" encoding="ISO-8859-1"?>
      <!DOCTYPE xsl:stylesheet [
          <!ENTITY newline "&#10;">
      ]>
      <!--XSL stylesheet to transform CppUnit XML output to JUnit XML -->

      <xsl:stylesheet version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

      <xsl:template match="/TestRun">
      <testsuite name="">
          <xsl:apply-templates select="SuccessfulTests/Test|FailedTests/FailedTest">
              <xsl:sort select="@id" data-type="number"/>
          </xsl:apply-templates>
      </testsuite>
      </xsl:template>

      <xsl:template match="FailedTest">
          <testcase>
              <xsl:attribute name="name">
                  <xsl:value-of select="Name"/>
              </xsl:attribute>
              <failure>
                  <xsl:value-of select="Message"/>
                  <xsl:value-of select="Location/File"/>:<xsl:value-of select="Location/Line"/>
              </failure>
          </testcase>
      </xsl:template>

      <xsl:template match="Test">
          <testcase>
              <xsl:attribute name="name">
                  <xsl:value-of select="Name"/>
              </xsl:attribute>
          </testcase>
      </xsl:template>

      </xsl:stylesheet>

       
    • Gayatri

      Gayatri - 2005-10-17

      I used this xsl to convert the cppunit test output to junit. This stylesheet is converting all the basic structure required by junit.

      <?xml version="1.0" encoding="UTF-8"?>
      <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
          <xsl:output method="xml" indent="yes"/>
          <xsl:template match="/">
              <testsuite>
                  <xsl:attribute name="errors">
                      <xsl:value-of select="TestRun/Statistics/Errors"/>
                  </xsl:attribute>
                  <xsl:attribute name="failures">
                      <xsl:value-of select="TestRun/Statistics/Failures"/>
                  </xsl:attribute>
                  <xsl:attribute name="tests">
                      <xsl:value-of select="TestRun/Statistics/Tests"/>
                  </xsl:attribute>
                  <xsl:attribute name="name">
                      <xsl:choose>
                      <xsl:when test="boolean(TestRun/SuccessfulTests/Test)" >
                          <xsl:variable name ="testPath" select="TestRun/SuccessfulTests/Test/Name"/>
                          <xsl:value-of select="substring-before($testPath,'::')"/>  
                      </xsl:when>
                      <xsl:otherwise>
                          <xsl:variable name ="testPath" select="TestRun/FailedTests/Test/Name"/>
                          <xsl:value-of select="substring-before($testPath,'::')"/> 
                      </xsl:otherwise>
                      </xsl:choose>
                  </xsl:attribute>
                  <xsl:apply-templates/>
              </testsuite>
          </xsl:template>
          <xsl:template match="/TestRun/SuccessfulTests/Test">
              <testcase>
                  <xsl:attribute name="classname" ><xsl:value-of select="substring-before(Name, '::')"/></xsl:attribute>
                  <xsl:attribute name="name"><xsl:value-of select="substring-after(Name, '::')"/></xsl:attribute>
              </testcase>
          </xsl:template>
          <xsl:template match="/TestRun/FailedTests/FailedTest">
              <testcase>
                  <xsl:attribute name="classname" ><xsl:value-of select="substring-before(Name, '::')"/></xsl:attribute>
                  <xsl:attribute name="name"><xsl:value-of select="substring-after(Name, '::')"/></xsl:attribute>
                  <error>
                      <xsl:attribute name="message">
                          <xsl:value-of select=" normalize-space(Message)"/>
                      </xsl:attribute>
                      <xsl:attribute name="type">
                          <xsl:value-of select="FailureType"/>
                      </xsl:attribute>
                      <xsl:value-of select="Message"/>
                      File:<xsl:value-of select="Location/File"/>
                      Line:<xsl:value-of select="Location/Line"/>
                      Data:<xsl:value-of select="Data/Name"/>
                      Data:<xsl:value-of select="Data/Value"/>       
                  </error>
              </testcase>
          </xsl:template>
        <!-- skip all text -->
          <xsl:template match="text()|@*"/>
      </xsl:stylesheet><!-- Stylus Studio meta-information - (c)1998-2001 eXcelon Corp.
      <metaInformation>
      <scenarios ><scenario default="yes" name="test" userelativepaths="yes" url="..\..\..\..\..\Tmp\xml\cppunit.xml" htmlbaseurl="" processortype="internal" commandline="" additionalpath="" additionalclasspath="" postprocessortype="none" postprocesscommandline="" postprocessadditionalpath="" postprocessgeneratedext=""/></scenarios><MapperInfo  srcSchemaPath="..\..\..\..\..\Tmp\xml\cppunit.xml" srcSchemaRoot="TestRun" srcSchemaPathIsRelative="yes" destSchemaPath="..\..\..\..\..\Tmp\xml\TEST&#x2D;test.osmoose.license.TestUtils.xml" destSchemaRoot="testsuite" destSchemaPathIsRelative="yes" />
      </metaInformation>
      -->

      I hope this will help.
      Thanks,
      Gayatri Picha

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.