CPPUnit & CruiseControl

2003-05-05
2003-05-29
  • Bernardo Sana

    Bernardo Sana - 2003-05-05

    Hi,

    does anybody have a link or can help help to integrate cruisecontrol and cppunit. I'm already running cruisecontrol in my MFC project (visual C).

    regards

    bernardo

     
    • Anonymous - 2003-05-29

      I would Also like to know the same help

       
    • Anonymous - 2003-05-29

      I do this by creating two separate Ant targets for each component I want to test with CppUnit, one for the component itself and another for it's unit tests.  I then create the third target which does nothing but depend on the others just to make sure that both the target for the component and the target for the tests are executed as part of the CruiseControl build process.

      The Ant buildfile contains something like this:

      <target name="mylib" depends="my_lib, mylib_tests" />

      <target name="my_lib">
        <cc outfile="libs/mylib">
          <fileset dir="mylib">
              <include name="*.cpp" />
          </fileset>
        </cc>
      </target>

      <target name="mylib_tests">
        <cc outfile="mylib_tests">
          <fileset dir="mylib/test"> <!-- Test files and test runner stored here -->
            <include name="*.cpp" />
          </fileset>
          <libset dir="libs" libs="mylib, cppunit" />
        </cc>

        <echo message="Running mylib unit tests" />
        <exec executable="mylib_tests" output="testresults/mylib_testlog.xml" />
      </target>

      I then make sure that the first target, mylib, is called as a part of the build process.  My build.xml contains the following:

      <target name="all">
        <antcall target="mylib" />
      </target>

      After execution, the test results are in the testresults folder.  To have CruiseControl collect the results, I put the following lines in the CC configuration file:

      <log dir="logs">
        <merge dir="testresults" />
      </log>

      Then remains the task of making CruiseControl recognizing the XML output of CppUnit.  I modified buildresults.jsp to include a stylesheet for the CppUnit output:

      <cruisecontrol:xsl xslFile="/xsl/unittests.xsl"/>

      My unittests.xsl is listed below.

      Of course, CppUnit has to be configured to use the XML outputter.

      I'm using RedHat with g++ 3.0.4.
      CruiseControl 2.0.1 and CppUnit 1.9.8.

      // tryggvi

      <?xml version="1.0"?>
      <xsl:stylesheet
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
          xmlns:lxslt="http://xml.apache.org/xslt">

          <xsl:output method="html"/>

          <xsl:variable name="test.top" select="cruisecontrol/TestRun"/>
          <xsl:variable name="test.stats" select="$test.top/Statistics"/>
          <xsl:variable name="totalTestRuns" select="count($test.top)"/>
          <xsl:variable name="totalErrorsAndFailures" select="count($test.top/FailedTests/FailedTest)"/>
          <xsl:variable name="testcase.failure.list" select="$test.top/FailedTests/FailedTest"/>
          <xsl:variable name="testsuite.failure.count" select="count($test.top/FailedTests/FailedTest)"/>

          <xsl:template match="/">
              <table align="center" cellpadding="2" cellspacing="0" border="0" width="98%">
                  <tr>
                      <td class="unittests-sectionheader" colspan="2">
                         &#160;Unit Tests:&#160;
                 (<xsl:value-of select="$totalTestRuns"/> testsuites)
                      </td>
                  </tr>

                  <xsl:choose>
                      <xsl:when test="count($test.top) = 0">
                          <tr>
                              <td colspan="2" class="unittests-data">
                                  No Tests Run
                              </td>
                          </tr>
                          <tr>
                              <td colspan="2" class="unittests-error">
                                  This project doesn't have any tests
                              </td>
                          </tr>
                      </xsl:when>
                  </xsl:choose>

                  <xsl:apply-templates select="$test.top"/>

                  <xsl:call-template name="testdetail">
                      <xsl:with-param name="detailnodes" select="$test.top"/>
                  </xsl:call-template>

                  <tr/>
             
              <tr><td colspan="2">&#160;</td></tr>
              <tr><td colspan="2">&#160;</td></tr>
              </table>
          </xsl:template>

          <xsl:template name="testdetail">
            <xsl:param name="detailnodes"/>

            <tr>
                <td class="unittests-sectionheader" colspan="2">
                          &#160;Unit Test Error Details:&#160;
               </td>
            </tr>

            <xsl:for-each select="$detailnodes/FailedTests/FailedTest">

              <tr>
                  <td colspan="2" class="unittests-data">
                      Test:&#160;<xsl:value-of select="Name"/>
                  </td>
              </tr>

              <tr>
                  <td colspan="2" class="unittests-data">
                      File:line: <xsl:value-of select="Location/File"/>:<xsl:value-of select="Location/Line"/>
                  </td>
              </tr>

              <tr>
                  <td colspan="2" class="unittests-error">
                      <pre>
                          <xsl:call-template name="br-replace">
                              <xsl:with-param name="word" select="Message"/>
                          </xsl:call-template>
                      </pre>
                  </td>
              </tr>

            </xsl:for-each>
          </xsl:template>

          <xsl:template match="TestRun">
              <tr>
                  <td class="unittests-data">
                      Test suite X (<xsl:value-of select="Statistics/Tests"/> testcases)
                  </td>
                  <td class="unittests-data">
                      <xsl:variable name="failCount">
                          <xsl:value-of select="Statistics/FailuresTotal"/>
                      </xsl:variable>
                      <xsl:if test="$failCount = 0">
                          All testcases passed.
                      </xsl:if>
                      <xsl:if test="$failCount > 0">
                          <xsl:value-of select="$failCount"/> testcase(s) failed.
                      </xsl:if>
                  </td>
              </tr>
          </xsl:template>

          <xsl:template name="br-replace">
              <xsl:param name="word"/>
      <xsl:variable name="cr"><xsl:text>
      </xsl:text></xsl:variable>
              <xsl:choose>
                  <xsl:when test="contains($word,$cr)">
                      <xsl:value-of select="substring-before($word,$cr)"/>
                      <br/>
                      <xsl:call-template name="br-replace">
                      <xsl:with-param name="word" select="substring-after($word,$cr)"/>
                      </xsl:call-template>
                  </xsl:when>
                  <xsl:otherwise>
                      <xsl:value-of select="$word"/>
                  </xsl:otherwise>
              </xsl:choose>
          </xsl:template>

      </xsl:stylesheet>

       

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks