Qaiser wrote:
Currently I am using Cobertura 1.8, ANT 1.6.2 for code Junit and code coverage. In my previous post i have asked about the solution of problem of generating Code coverage from cobertura.
<!--adding cobertura support for Code coverage-->
<property name="classes_cobertura" value="${build_results}/classes_cobertura" />
<property name="instrumented_classes" value="${build_results}/instrumented_classes" />
<property name="reports_cobertura" value="${build_results}/reports_cobertura" />
<!-- ======================================================== -->
<!-- Cobertura classpath -->
<!-- ======================================================== -->
<!-- Define cobertura classpath-->
<path id="cobertura.classpath">
<fileset dir="${buildtools}/cobertura">
<include name="cobertura.jar" />
<include name="**/*.jar" />
</fileset>
</path>
<!-- **** To be able to use the cobertura-instrument task **** -->
<taskdef classpathref="cobertura.classpath" resource="tasks.properties" />
<!--Initialize cobertura -->
<target name="init_cobertura"
description="create the directories needed for cobertura">
<echo message="Creating the directories needed for cobertura"/>
<tstamp>
<format property="man-date" pattern="E dd MM yyyy hh:mm:ss aa z" locale="EN"/>
</tstamp>
<mkdir dir="${build_results}"/>
<mkdir dir="${classes_cobertura}"/>
<mkdir dir="${testoutput}"/>
<mkdir dir="${reports_cobertura}"/>
</target>
<target name="compileonly_cobertura" depends="init,init_cobertura"
description="compile the source for cobertura" >
<echo message="compiling source code in ${src}"/>
<echo message="excluding files listed in ${exclude.xml}"/>
<javac srcdir="${src}"
destdir="${classes_cobertura}"
listfiles="${javac.list}"
debug="${debug.flag}"
debuglevel="vars,lines,source"
nowarn="no"
deprecation="no"
includesfile="${include.xml}"
excludesfile="${exclude.xml}">
<classpath refid="powerexplorer.classpath" />
<classpath refid="PE.classpath" />
<classpath refid="DEPENDENCY.classpath" />
<classpath refid="MOJO.classpath" />
</javac>
</target>
<target name="copy_cobertura" depends="compileonly_cobertura"
description="copies contents of copy.xml data file, and creates CompileTime.txt file " >
<echo message="copying contents of ${copy.xml} data file"/>
<copy todir="${classes_cobertura}" >
<fileset dir="${src}"
includesfile="${copy.xml}"
excludes="**/Makefile" />
</copy>
<echo message="creating ${timestampfile_cobertura} file"/>
<echo file="${timestampfile_cobertura}"
message="${man-date}" >
</echo>
</target>
<target name="test_cobertura" depends="compileonly_cobertura"
description="runs JUnit tests based on Cobertura instrumented classes" >
<echo message="running JUnit tests"/>
<junit printsummary="on"
dir="${PE_DEV_ROOT}"
haltonfailure="off"
haltonerror="off"
failureproperty="test.failed"
timeout="${junit.timeout}"
fork="on"
maxmemory="1024m"
showoutput="true">
<env key="DISPLAY" value="134.132.108.153:0.0"/>
<!-- Set Path/LD_LIBRARY_PATH to find native libraries -->
<env key="${os.libpath.name}" path="${SystemPath};${os.libpath}" />
<sysproperty key="TEST_PROPERTY_FILE" value="${test.prop.file}"/>
<sysproperty key="PE_DEV_ROOT" value="${basedir}"/>
<sysproperty key="java.util.logging.config.file" value="${logging.config}"/>
<formatter type="plain" usefile="false" />
<formatter type="xml" usefile="true" />
<batchtest todir="${testoutput}"
filtertrace="off">
<fileset dir="${src}">
<includesfile name="${tests.include}"/>
<excludesfile name="${tests.exclude}"/>
</fileset>
</batchtest>
<!-- Specify the name of the coverage data file to use. -->
<!-- sysproperty key="net.sourceforge.cobertura.datafile" file="${basedir}/cobertura.ser" / -->
<!-- Note the classpath order: instrumented classes are before the
original (uninstrumented) classes. This is important. -->
<classpath>
<pathelement path="${instrumented-classes}" />
<pathelement path="${build_results}/classes_cobertura" />
<pathelement path="${PE_classpath}" />
<pathelement path="${powerexplorer.classpath}" />
</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" />
<!--classpath refid="powerexplorer.classpath" />
<classpath refid="DEPENDENCY.classpath"/>
<classpath refid="MOJO.classpath"/-->
</junit>
<echo message="running JUnit Reports"/>
<junitreport todir="${reports_cobertura}">
<fileset dir="${reportdir}" >
<include name="TEST*.xml" />
</fileset>
<report format="frames" todir="${reports_cobertura}" />
</junitreport>
<echo message="To see your Junit results, please open ${reports_cobertura}/index.html}"/>
</target>
<target name="init-coverage" description="Initialize coverage used by Cobertura">
<mkdir dir="${build_results}/coverage"/>
<mkdir dir="${build_results}/coverage/xml"/>
<mkdir dir="${build_results}/coverage/html"/>
<mkdir dir="${instrumented_classes}"/>
<mkdir dir="${classes_cobertura}"/>
</target>
<target name="instrumented" depends="init-coverage,compileonly_cobertura">
<echo message="************* Instrumentation is under process ******************"/>
<delete dir="${basedir}/cobertura.ser"/>
<delete dir="${instrumented_classes}"/>
<!--
Instrument the application classes, writing the
instrumented classes into ${build.instrumented.dir}
-->
<cobertura-instrument todir="${instrumented_classes}">
<!--
The following line causes instrument to ignore any
source line containing a refernce to log4j, for the
purpose of coverage reporting.
-->
<ignore regex="org.apache.log4j.*"/>
<!--Add all classes giving trouble due to serialization and serialVersionUID -->
<ignore regex="com.pgs.dm.slegge.server.interfaces.*" />
<ignore regex="com.pgs.dm.slegge.server.rmi.*" />
<!-- Current hack to get Cobertura going on a little more classes - nt good but just trying -->
<ignore regex="com.lgc.dam.phs.client.*" />
<classpath refid="cobertura.classpath"/>
<fileset dir="${classes_cobertura}">
<!--
Instrument all the application classes,
but don't instrument the test classes.
-->
<include name="**/*.class"/>
<exclude name="**/test/*.class"/>
</fileset>
</cobertura-instrument>
</target>
<target name="coverage-report" depends="clean-coverage,compileonly_cobertura,init-coverage,instrumented,test_cobertura"
description="Create the Cobertura reports">
<echo message="*********************Running Coverage reports************************"/>
<cobertura-report srcdir="${src}"
format="html"
destdir="${build_results}/coverage/html">
<classpath refid="cobertura.classpath"/>
</cobertura-report>
</target>
<target name="clean-coverage">
<delete dir="${build_results}/coverage"/>
<delete dir="${build_results}/coverage/xml"/>
<delete dir="${build_results}/coverage/html"/>
<delete dir="${instrumented_classes}"/>
<delete dir="${classes_cobertura}"/>
<delete dir="build_results/tests" />
<delete file="${basedir}/cobertura.ser" />
</target>
I have invested too much time on it but did not find any solution to this problem.javascript:Nabble.smiley('smiley_sad.gif',':-((')Sad Even my unit test are working fine but the code coverage report always show 0% code coverage.
Please have a look into my build.xml and tell me where i am missing something.
Thanks in advance,
--Qaiser
I have got the solution as i was using wrong instrumented classpath instrumented target.
<classpath>
<pathelement path="${instrumented_classes}" />
<pathelement path="${build_results}/classes_cobertura" />
<pathelement path="${PE_classpath}" />
<pathelement path="${powerexplorer.classpath}" />
</classpath>
--Thanks