Re: Possible to use with Cobertura?

Ryan <[email protected]>
Newsgroups gmane.comp.jakarta.cactus.user
Message-ID <[email protected]>
Here are snippits of my build.xml.  I have gone over and over it and still
cannot find the reason why Cobertura reports 0% coverage for my servlet tests. 
The tests run ok and the "unit-test-results" are created, but it seems that the
test are not being saved to the cobertura.ser file.  That is my guess at least.
 What am I doing wrong?  Very frustrated, and again, thanks fort he help.

...

<!-- Setup cobertura instrumented test classes -->
  <target name="code-coverage-setup" depends="compile">
    <delete file="${coberturaDataFile}"/>
    <delete dir="${instDir}"/>
    <mkdir dir="${testingDir}"/>
    <!-- build instrumented class files for code coverage testing -->
    <cobertura-instrument todir="${instDir}" datafile="${coberturaDataFile}">
      <ignore regex="org.apache.log4j.*" />
      <fileset dir="${buildDir}">
        <include name="**/*.class"/>
        <exclude name="**/*Test.class"/>
        <exclude name="**/test/*"/>
      </fileset>
    </cobertura-instrument>
  </target>

...

  <target name="code-coverage-report">
    <!--Generate a series of HTML files containing the coverage
    data in a user-readable form using nested source filesets.-->
    <cobertura-report datafile="${coberturaDataFile}"
                      destdir="${codeCoverageReportDir}">
      <fileset dir="${srcJavaDir}">
        <include name="**/*.java"/>
        <exclude name="**/*Test.java"/>
        <exclude name="**/test/*"/>
      </fileset>
    </cobertura-report>
  </target>

...

<!-- Run to setup instrumented class files, run unit tests and generate coverage
                  reports-->
  <target name="test" depends="unittest, code-coverage-report"/>

    <!-- unit testing -->
    <target name="unittest" depends="code-coverage-setup">
    <!-- clean the test-results folder -->
    <delete dir="${unitTestResultsDir}"/>
    <!-- create the test-results folder -->
    
    <mkdir dir="${unitTestResultsDir}/cactus"/>
    
    <!-- invoke cactus -->
    <cactus warfile="${distDir}/${warName}-cactified.war" 
            fork="yes" 
            haltonfailure="no" 
            failureproperty="tests.failed">
      <!--
        Specify the name of the coverage data file to use.
        The value specified below is the default.
       -->
      <sysproperty key="net.sourceforge.cobertura.datafile"
                   file="${coberturaDataFile}"/>
      <!--
        Note the classpath order: instrumented classes are before the
        original (uninstrumented) classes.  This is important.
       -->
      <classpath>
        <pathelement path="${instDir}"/>
        <pathelement path="${buildDir}"/>
        <pathelement path="${buildDir}/Cactus"/>
        <pathelement path="${cobertura.dir}/cobertura.jar"/>
      </classpath>
      
      <!--
        The instrumented classes reference classes used by the
        Cobertura runtime, so Cobertura and its dependencies
        must be on your classpath.
      -->
      <classpath refid="cobertura.classpath"/>
      
      
      <containerclasspath>
        <pathelement location="${cobertura.dir}/cobertura.jar"/>
      </containerclasspath>
      
      <!-- set log4j.configuration system property -->
      <jvmarg value="-Dlog4j.configuration=file:${testLoggingProperties}"/>
      
      <!-- define the classpath 
      <classpath refid="project.class.path"/>-->
     
    
    <classpath>
      <path refid="project.class.path"/>
      
      
      <pathelement location="${cobertura.dir}/cobertura.jar"/>
      <pathelement location="${cactus.dir}/lib/httpunit-1.6.jar"/>
      <pathelement location="${cactus.dir}/lib/nekohtml-0.9.1.jar"/>
      <pathelement location="${thirdPartyLibsDir}"/>
    </classpath>
    
    <!-- define the formatter -->
    <formatter type="brief" usefile="false"/>
    <formatter type="plain"/>
    
    
    <containerset>
      <tomcat5x if="cactus.home.tomcat5x"
        dir="${cactus.home.tomcat5x}"
        port="${cactus.port}"
        output="${testingDir}/cactus.out"
        todir="${unitTestResultsDir}/cactus"
        serverxml="${cactus.home.tomcat5x}/conf/server.xml"/>
        
    </containerset>
    
    <!-- setup for batch-testing -->
    <batchtest fork="yes" todir="${unitTestResultsDir}">
      <fileset dir="${buildDir}/Cactus">
		<include name="**/*ServletTest.class"/>
	  </fileset>
    </batchtest>   
  </cactus>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.