0

I'm using Cobertura 1.9.4 with NetBeans 7.2.1, Ant 1.8.3 and JDK 1.7.0_05 with JUnit 4.10.

My HTML coverage reports are being generated, but they all list 0% unit test coverage. This shouldn't be the case because I have unit test that cover my entire util class.

What's interesting is all my unit test start to fail if I include the instrumented classes in my test path by changing

run.test.classpath=\
    ${javac.test.classpath}:\
    ${build.test.classes.dir}

to

run.test.classpath=\
    ${build.instrumented.dir}:\
    ${javac.test.classpath}:\
    ${build.test.classes.dir}

Also, if I turn on the emma code coverage tool all my test cases will break as well.

NOTE: There is a nearly identical post Cobertura showing 0% coverage but since it is unanswered, slightly dated and my configuration differs I thought I'd capture my setup here. Here are two references that are similar to my config: 1)cobertura pdf 2)NetBeans CoberaturaAnt Wiki

Snipped from my build.xml

<!-- this strangely doesn't work so i'm temporarily using hardcoded path below
<taskdef classpath="cobertura.jar"  resource="tasks.properties" />
 -->

<path id="cobertura.class.path">
    <pathelement location="libs/cobertura.jar" />
    <pathelement location="libs/asm-3.0.jar" />
    <pathelement location="libs/asm-tree-3.0.jar" />
    <pathelement location="libs/log4j-1.2.9.jar" />
    <pathelement location="libs/jakarta-oro-2.0.8.jar" />
</path>
<taskdef resource="tasks.properties" classpathref="cobertura.class.path" />

<target depends="-init-check,init" name="-init-check-cobertura">
    <fail unless="build.classes.dir">Must set build.classes.dir</fail>
</target>

<target name="-post-compile" depends="-init-check-cobertura,init">
    <delete dir="${build.instrumented.dir}" />
    <delete dir="${build.test.coverage.dir}" />
    <mkdir dir="${build.instrumented.dir}" />
    <mkdir dir="${build.test.coverage.dir}" />
    <cobertura-instrument todir="${build.instrumented.dir}" 
                          datafile="${build.dir}/cobertura.ser">
        <fileset dir="${build.classes.dir}">
            <include name="**/*.class"/>
        </fileset>
    </cobertura-instrument>
</target>

<target name="coverage-report" depends="test">
    <cobertura-report format="html" destdir="${build.test.coverage.dir}"
                                    datafile="${build.dir}/cobertura.ser"/>
    <delete file="${build.dir}/cobertura.ser" />
    <delete dir="${build.instrumented.dir}" />
</target>

I've also defined these in my project.properties file

build.instrumented.dir=${build.dir}/instrumented
build.test.coverage.dir=${build.dir}/test/coverage

FYI I already tried adding these to my tag in build-impl.xml. still zero coverage.

<jvmarg value="-Dcobertura.use.java.nio=false"/>
<jvmarg value="-Dnet.sourceforge.cobertura.datafile=${basedir}/cobertura.ser"/>

The ant test target is from the netbeans generated build-impl.xml file

<target depends="init,compile-test,-pre-test-run,-do-test-run,test-report,-post-test-run,-test-browse" 
     description="Run unit tests." name="test"/>
Community
  • 1
  • 1
simgineer
  • 1,754
  • 2
  • 22
  • 49

0 Answers0