views:

83

answers:

0

Hi folks,

I'm using Cobertura 1.9.3 with NetBeans 6.8, Ant 1.7.1 and JDK 1.6.0_21 running with -WAR, and EJB, JUnit 4 tests.

When I change the line "pathelement location="${build.classes.dir}" /" to "pathelement location="${build.test.classes.dir}" /", there is some coverage (albeit in the wrong classes, it shouldn't be in the testclass, just to show that the environment and .jar locations are set correctly) shown in the html reports.

However, when I change it back to "pathelement location="${build.classes.dir}" /", I always get 0% coverage.

fwiw, when the instrumentation folders do contain instrumented classes in ${build.instrumented.dir} (these classes are slightly larger than the ones in the ${build.classes.dir} location). And yes, I've retried after deleting cobertura.ser from the previous run.

Could I please have a clue on what's wrong?

Cheers,

Snippet of build.xml in a -ejb folder.

           <property environment="env"/>
           <path id="cobertura.class.path">
               <fileset dir="${build.dir}/../../lib">
                   <include name="**/*.jar"/>
               </fileset>
           </path>
           <taskdef classpathref="cobertura.class.path" resource="tasks.properties"/>

           <target name="-pre-compile-test">
               <delete dir="${build.instrumented.dir}" />
               <delete dir="${build.report.cobertura.dir}" />
               <mkdir dir="${build.instrumented.dir}" />
               <mkdir dir="${build.report.cobertura.dir}" />
               <cobertura-instrument todir="${build.instrumented.dir}" classpathref="cobertura.class.path">
                   <ignore regex="org.apache.log4j.*" />
                   <includeClasses regex=".*" />
                   <excludeClasses regex=".*\.Test.*" />
                   <excludeClasses regex=".*\.TestSuite.*" />

                   <instrumentationClasspath>
                       <pathelement location="${build.classes.dir}" />
                   </instrumentationClasspath>
               </cobertura-instrument>
           </target>

           <target name="-post-test-run">
               <cobertura-report format="html" srcdir="${src.dir}" destdir="${build.report.cobertura.dir}"/>
               <cobertura-report format="xml" srcdir="${src.dir}" destdir="${build.report.cobertura.dir}"/>
           </target>

===

Edit: I also have the following set up:

        ...
        build.test.classes.dir=${build.dir}/test/classes
        build.test.results.dir=${build.dir}/test/results
        build.instrumented.dir=${build.dir}/instrumented
        build.report.dir=${build.dir}/report
        build.report.cobertura.dir=${build.report.dir}/cobertura
        ...
        javac.classpath=\
        ${libs.GlassFish_v3.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}
        ...
        javac.test.classpath=\
        ${javac.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}:\
        ${libs.Libraries_Needed_For_JUnit.classpath}:\
        ${build.instrumented.dir}:\
        ${build.classes.dir}:\
        ${libs.junit_4.classpath}
        ...
        run.test.classpath=\
        ${javac.test.classpath}:\
        ${file.reference.mysql-connector-java-5.1.13-bin.jar}:\
        ${libs.Cobertura.classpath}:\
        ${libs.Libraries_Needed_For_JUnit.classpath}:\
        ${libs.junit_4.classpath}:\
        ${build.test.classes.dir}
        ...
        src.dir=${source.root}/java
        test.src.dir=test