ptmcomp
asked on
Creating Cobertura report with Ant
Hi experts!
I'm trying to create a cobertura report with ant. I tried all the examples from the web but I'm always getting a 0% coverage report.
I'm using Ant 1.6.5, JUnit 3.8.1 and cobertura 1.8
The JUnit test report shows that the tests were executed and successfull. The cobertura report shows the right class, but 0% coverage. I also tried to delete the original classes or overwrite them with the instrumented classes - no change...
My build.xml file looks like this:
<?xml version="1.0"?>
<project name="CoberturaAntScript" default="all" basedir=".">
<description>
Tests the creation of a Cobertura report
</description>
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="libs" location="." />
<property name="src.tests" location="test" />
<property name="build" location="build" />
<property name="build.instrumented" location="build-instrument ed" />
<property name="cobertura.ser" location="D:/Data/Code/Jav a/TestProj ects/Cober turaTest/C oberturaTe st/reports /cobertura .ser" />
<property name="build.tests" location="build.tests" />
<property name="reports" location="./reports" />
<property name="reports.tests.html" location="${reports}/unit- tests/html " />
<property name="reports.tests.xml" location="${reports}/unit- tests/xml" />
<property name="reports.coveragerepo rt" location="reports/coverage report" />
<property name="dist" location="dist" />
<property name="cobertura.dir" value="D:/Data/Code/Java/s ourceforge /cobertura /cobertura -1.8" />
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.cl asspath" resource="tasks.properties " />
<path id="classpath.base">
<path refid="cobertura.classpath " />
<fileset dir="${libs}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="classpath.test">
<path refid="classpath.base" />
<pathelement location="${build}" />
<pathelement location="${build.tests}" />
<pathelement location="D:/Data/Code/Jav a/apache/a pache-ant- 1.6.5/lib/ junit.jar" />
<pathelement location="D:/Data/Code/Jav a/apache/a pache-ant- 1.6.5/lib/ ant-junit. jar" />
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${build.tests}" />
<mkdir dir="${reports}" />
<mkdir dir="${dist}" />
</target>
<target name="compile" depends="init" description="compile the source ">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" classpathref="classpath.ba se" debug="true">
<include name="**/*.java" />
</javac>
</target>
<target name="compile-tests" depends="init" description="compile the source ">
<javac srcdir="${src.tests}" destdir="${build.tests}" classpathref="classpath.te st" debug="true">
<include name="**/*Test*.java" />
</javac>
</target>
<target name="cobertura-instrument " depends="compile-tests">
<delete file="${cobertura.ser}" />
<delete dir="${build.instrumented} " />
<cobertura-instrument datafile="${cobertura.ser} " todir="${build.instrumente d}">
<ignore regex="org.apache.log4j.*" />
<fileset dir="${build}">
<include name="**/*.class" />
</fileset>
<!--
<fileset dir="${libs}">
<include name="my-own-library.jar" />
</fileset>
-->
</cobertura-instrument>
</target>
<target name="unit-test" depends="cobertura-instrum ent">
<mkdir dir="${reports.tests.xml}" />
<junit fork="yes" printsummary="yes" haltonfailure="yes">
<sysproperty key="net.sourceforge.cober tura.dataf ile" file="${cobertura.ser}" />
<classpath refid="cobertura.classpath " />
<classpath location="${build.instrume nted}" />
<classpath location="${build.tests}" />
<batchtest fork="yes" todir="${reports.tests.xml }">
<fileset dir="${build.tests}">
<include name="**/*Test*.class" />
</fileset>
<formatter type="xml" usefile="true" />
</batchtest>
</junit>
</target>
<target name="unit-test-report">
<mkdir dir="${reports.tests.html} " />
<junitreport todir="${reports.tests.xml }">
<fileset dir="${reports.tests.xml}" >
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${reports.tests.htm l}" />
</junitreport>
</target>
<target name="cobertura-report">
<cobertura-report format="html" datafile="${cobertura.ser} " destdir="${reports.coverag ereport}" srcdir="${src}" />
</target>
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib" />
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyPro ject-${DST AMP}.jar" basedir="${build}" />
</target>
<target name="clean" description="clean up">
<delete dir="${build}" />
<delete dir="${build.instrumented} " />
<delete dir="${build.tests}" />
<delete dir="${reports}" />
<delete dir="${dist}" />
</target>
<target name="all" depends="clean,init,compil e,compile- tests,cobe rtura-inst rument,uni t-test,uni t-test-rep ort,cobert ura-report " />
</project>
I would appreciate any hint.
Thank you
René Grob
I'm trying to create a cobertura report with ant. I tried all the examples from the web but I'm always getting a 0% coverage report.
I'm using Ant 1.6.5, JUnit 3.8.1 and cobertura 1.8
The JUnit test report shows that the tests were executed and successfull. The cobertura report shows the right class, but 0% coverage. I also tried to delete the original classes or overwrite them with the instrumented classes - no change...
My build.xml file looks like this:
<?xml version="1.0"?>
<project name="CoberturaAntScript" default="all" basedir=".">
<description>
Tests the creation of a Cobertura report
</description>
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="libs" location="." />
<property name="src.tests" location="test" />
<property name="build" location="build" />
<property name="build.instrumented" location="build-instrument
<property name="cobertura.ser" location="D:/Data/Code/Jav
<property name="build.tests" location="build.tests" />
<property name="reports" location="./reports" />
<property name="reports.tests.html" location="${reports}/unit-
<property name="reports.tests.xml" location="${reports}/unit-
<property name="reports.coveragerepo
<property name="dist" location="dist" />
<property name="cobertura.dir" value="D:/Data/Code/Java/s
<path id="cobertura.classpath">
<fileset dir="${cobertura.dir}">
<include name="cobertura.jar" />
<include name="lib/**/*.jar" />
</fileset>
</path>
<taskdef classpathref="cobertura.cl
<path id="classpath.base">
<path refid="cobertura.classpath
<fileset dir="${libs}">
<include name="**/*.jar" />
</fileset>
</path>
<path id="classpath.test">
<path refid="classpath.base" />
<pathelement location="${build}" />
<pathelement location="${build.tests}" />
<pathelement location="D:/Data/Code/Jav
<pathelement location="D:/Data/Code/Jav
</path>
<target name="init">
<!-- Create the time stamp -->
<tstamp />
<!-- Create the build directory structure used by compile -->
<mkdir dir="${build}" />
<mkdir dir="${build.tests}" />
<mkdir dir="${reports}" />
<mkdir dir="${dist}" />
</target>
<target name="compile" depends="init" description="compile the source ">
<!-- Compile the java code from ${src} into ${build} -->
<javac srcdir="${src}" destdir="${build}" classpathref="classpath.ba
<include name="**/*.java" />
</javac>
</target>
<target name="compile-tests" depends="init" description="compile the source ">
<javac srcdir="${src.tests}" destdir="${build.tests}" classpathref="classpath.te
<include name="**/*Test*.java" />
</javac>
</target>
<target name="cobertura-instrument
<delete file="${cobertura.ser}" />
<delete dir="${build.instrumented}
<cobertura-instrument datafile="${cobertura.ser}
<ignore regex="org.apache.log4j.*"
<fileset dir="${build}">
<include name="**/*.class" />
</fileset>
<!--
<fileset dir="${libs}">
<include name="my-own-library.jar" />
</fileset>
-->
</cobertura-instrument>
</target>
<target name="unit-test" depends="cobertura-instrum
<mkdir dir="${reports.tests.xml}"
<junit fork="yes" printsummary="yes" haltonfailure="yes">
<sysproperty key="net.sourceforge.cober
<classpath refid="cobertura.classpath
<classpath location="${build.instrume
<classpath location="${build.tests}" />
<batchtest fork="yes" todir="${reports.tests.xml
<fileset dir="${build.tests}">
<include name="**/*Test*.class" />
</fileset>
<formatter type="xml" usefile="true" />
</batchtest>
</junit>
</target>
<target name="unit-test-report">
<mkdir dir="${reports.tests.html}
<junitreport todir="${reports.tests.xml
<fileset dir="${reports.tests.xml}"
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${reports.tests.htm
</junitreport>
</target>
<target name="cobertura-report">
<cobertura-report format="html" datafile="${cobertura.ser}
</target>
<target name="dist" depends="compile" description="generate the distribution">
<!-- Create the distribution directory -->
<mkdir dir="${dist}/lib" />
<!-- Put everything in ${build} into the MyProject-${DSTAMP}.jar file -->
<jar jarfile="${dist}/lib/MyPro
</target>
<target name="clean" description="clean up">
<delete dir="${build}" />
<delete dir="${build.instrumented}
<delete dir="${build.tests}" />
<delete dir="${reports}" />
<delete dir="${dist}" />
</target>
<target name="all" depends="clean,init,compil
</project>
I would appreciate any hint.
Thank you
René Grob
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Sometimes the problem is sitting in front of the computer screen...
Well, the ant script is fine - just the test methods were commented out, so there was actually 0% coverage! I wasted so much time with this!
Anyway thank you for your help!
René
Well, the ant script is fine - just the test methods were commented out, so there was actually 0% coverage! I wasted so much time with this!
Anyway thank you for your help!
René
Yes, it helps when you run in debug mode ;-)
ASKER
Apache Ant version 1.6.5 compiled on June 2 2005
Apache Ant version 1.6.5 compiled on June 2 2005
Buildfile: build.xml
Detected Java version: 1.5 in: C:\Java\jdk1.5.0_04\jre
Detected OS: Windows XP
parsing buildfile D:\Data\Code\Java\TestProj
Project base dir set to: D:\Data\Code\Java\TestProj
Build sequence for target(s) `all' is [clean, init, compile, compile-tests, cobertura-instrument, unit-test, unit-test-report, cobertura-report, all]
Complete build sequence is [clean, init, compile, compile-tests, cobertura-instrument, unit-test, unit-test-report, cobertura-report, all, tests-only, prepare, dist, ]
clean:
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
[delete] Deleting directory D:\Data\Code\Java\TestProj
init:
[mkdir] Created dir: D:\Data\Code\Java\TestProj
[mkdir] Created dir: D:\Data\Code\Java\TestProj
[mkdir] Created dir: D:\Data\Code\Java\TestProj
[mkdir] Created dir: D:\Data\Code\Java\TestProj
compile:
[javac] com\mycompany\myproject\Cl
[javac] Compiling 1 source file to D:\Data\Code\Java\TestProj
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-classpath'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-sourcepath'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-g'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] File to be compiled:
[javac] D:\Data\Code\Java\TestProj
compile-tests:
[javac] com\mycompany\myproject\te
[javac] Compiling 1 source file to D:\Data\Code\Java\TestProj
[javac] Using modern compiler
[javac] Compilation arguments:
[javac] '-d'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-classpath'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-sourcepath'
[javac] 'D:\Data\Code\Java\TestPro
[javac] '-g'
[javac]
[javac] The ' characters around the executable and arguments are
[javac] not part of the command.
[javac] File to be compiled:
[javac] D:\Data\Code\Java\TestProj
cobertura-instrument:
[delete] Could not find file D:\Data\Code\Java\TestProj
Adding com\mycompany\myproject\Cl
[cobertura-instrument] Executing 'C:\Java\jdk1.5.0_04\jre\b
[cobertura-instrument] '-classpath'
[cobertura-instrument] 'D:\Data\Code\Java\sourcef
[cobertura-instrument] 'net.sourceforge.cobertura
[cobertura-instrument] '--commandsfile'
[cobertura-instrument] 'C:\DOKUME~1\rg\LOKALE~1\T
[cobertura-instrument]
[cobertura-instrument] The ' characters around the executable and arguments are
[cobertura-instrument] not part of the command.
[cobertura-instrument] Cobertura 1.8 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-instrument] Instrumenting 1 file to D:\Data\Code\Java\TestProj
[cobertura-instrument] Cobertura: Saved information on 1 classes.
[cobertura-instrument] Instrument time: 109ms
unit-test:
[mkdir] Created dir: D:\Data\Code\Java\TestProj
[junit] Implicitly adding D:\Data\Code\Java\apache\a
[junit] Running com.mycompany.myproject.te
[junit] Executing 'C:\Java\jdk1.5.0_04\jre\b
[junit] '-Dnet.sourceforge.cobertu
[junit] '-classpath'
[junit] 'D:\Data\Code\Java\sourcef
[junit] 'org.apache.tools.ant.task
[junit] 'com.mycompany.myproject.t
[junit] 'filtertrace=true'
[junit] 'haltOnError=false'
[junit] 'haltOnFailure=true'
[junit] 'formatter=org.apache.tool
[junit] 'showoutput=false'
[junit] 'formatter=org.apache.tool
[junit] 'propsfile=D:\Data\Code\Ja
[junit]
[junit] The ' characters around the executable and arguments are
[junit] not part of the command.
[junit] Tests run: 2, Failures: 0, Errors: 0, Time elapsed: 0.047 sec
unit-test-report:
[mkdir] Created dir: D:\Data\Code\Java\TestProj
[junitreport] Parsing file: 'D:\Data\Code\Java\TestPro
[junitreport] Using com.sun.org.apache.xalan.i
[junitreport] Transform time: 500ms
cobertura-report:
[cobertura-report] Executing 'C:\Java\jdk1.5.0_04\jre\b
[cobertura-report] '-classpath'
[cobertura-report] 'D:\Data\Code\Java\sourcef
[cobertura-report] 'net.sourceforge.cobertura
[cobertura-report] '--commandsfile'
[cobertura-report] 'C:\DOKUME~1\rg\LOKALE~1\T
[cobertura-report]
[cobertura-report] The ' characters around the executable and arguments are
[cobertura-report] not part of the command.
[cobertura-report] Cobertura 1.8 - GNU GPL License (NO WARRANTY) - See COPYRIGHT file
[cobertura-report] Cobertura: Loaded information on 1 classes.
[cobertura-report] Report time: 391ms
all:
BUILD SUCCESSFUL
Total time: 4 seconds