Cobertura showing 0% coverage
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}/..开发者_如何学C/../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
The only case when you get 0% coverage is
- When you have not set your classpath correctly, your tests are running against non instrumented code, or,
- Your .ser (metadata) file is stale, whenever you build/rebuild your code, you should delete the existing metadata file and instrument again.
See here for a good example on classpath https://github.com/cobertura/cobertura/wiki/Ant-Task-Reference
Also, it's a good idea to keep instrumented classes in a separate folder, as well as specify a different folder for test classes.
精彩评论