Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Clover shows zero coverage when run from ant build file , but in eclipse shows coverage percentage.

Padma G November 20, 2014
<target name="execute-tests" description="run your test suite">
 <junit printsummary="yes" haltonfailure="no" showoutput="yes" dir="${testsrc}/tests">
 <classpath>
 <path refid="junit.classpath"/>
 <pathelement path="${testsrc}/tests"/> 
 </classpath>
 <batchtest fork="yes" todir="${reports}/raw/" errorproperty="junit.errors" failureproperty="junit.failures">
 <formatter type="xml"/>
 <fileset dir="${testdir1l}">
 <include name="**/*Test.java"/>
 </fileset>
 <fileset dir="${testdir2}">
 <include name="**/*Test.java"/>
 </fileset>
 <fileset dir="${testdir3}">
 <include name="**/*Test.java"/>
 </fileset>
<target name="with.clover">
 <clover-setup initString="${clover.db}">
</clover-setup> 
 
</target>
<target name="clover.report">
 <clover-report initstring="${src}/target/clover/database/clover.db"> 
 <current outfile="${src}/target/site/clover/clover.xml" />
 <current outfile="${src}/target/site/clover">
 
 <format type="html"/>
 </current>
</clover-report>
</target>

 

The tests are different directories. What do I need to do to show the coverage correctly?

 

1 answer

0 votes
Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 21, 2014

What Ant command did you run? I'm asking because you must recompile your classes with Clover. For instance:

ant clean with.clover compile execute-tests clover.report

(assuming that your build file has "clean" and "compile" targets).

 

Do you have clover.jar declared in your junit.classpath? I'm asking because clover.jar must be available at runtime.

 

You call clover-setup with the following path to Clover database:

<clover-setup initString="${clover.db}">

but next for reporting you're using probably a different path:

<clover-report initstring="${src}/target/clover/database/clover.db">

Does "${clover.db}" point to the same location as "${src}/target/clover/database/clover.db"?

 

Padma G November 21, 2014

Thank you for your response. This is snippet of the build file. a bit changed , but we have several testdirs located in multiple directories. There is no clean target, but we have init which does clean and make directories instead ant -buildfile build_junit.xml with.clover run-tests clover.report I am having no clue why it shows zero always. run-tests target runs init, compile, execute and report of unit tests. <?xml version="1.0" encoding="windows-1252" ?> <project xmlns="antlib:org.apache.tools.ant" name="Tests" default="run-tests" basedir="."> <property name="src" location="."/> <property name="CLOVER_HOME" location="${src}\..\..\build\clover"/> <property name="build" location="${src}/bin"/> <property name="dist" location="${src}/dist"/> <property name="testsrc" location="${src}/test"/> <property name="testdir1" location="${src}/testdir1/xyz/test/"/> <property name="testdir2" location="${src}/testdir2/pqr/test"/> <property name="reports" location="${src}/reports"/> <property name="clover.db" location="${src}/target/clover/database/clover.db"/> <property name="clover.jar" location="${CLOVER_HOME}/clover.jar"/> <taskdef resource="cloverlib.xml" classpath="${clover.jar}"/> <import file="junit_includes.xml" /> <target name="init"> <tstamp/> <delete includeemptydirs="true" quiet="true"><fileset dir="${reports}"/></delete> <delete includeemptydirs="true" quiet="true"><fileset dir="${testsrc}"/></delete> <mkdir dir="${reports}"/> <mkdir dir="${reports}/raw/"/> <mkdir dir="${reports}/html/"/> <mkdir dir="${testsrc}"/> <mkdir dir="${testsrc}/tests"/> <mkdir dir="${testsrc}/Config"/> <mkdir dir="${src}/target"/> </target> <target name="compile-tests" depends="init"> <javac srcdir="${src}" destdir="${testsrc}/tests" debug="true"> <include name="Common/**/*.java"/> <include name="xyz/**/*.java"/> <classpath refid="junit.classpath"/> </javac> <copy todir="${testsrc}/tests"> <fileset dir="${testdir1}" excludes="**/*.java"/> <fileset dir="${testdir2}" excludes="**/*.java"/> </copy> </target> <target name="execute-tests" description="run your test suite"> <junit printsummary="yes" haltonfailure="no" showoutput="yes" dir="${testsrc}/tests"> <classpath> <path refid="junit.classpath"/> <pathelement path="${testsrc}/tests"/> </classpath> <batchtest fork="yes" todir="${reports}/raw/" errorproperty="junit.errors" failureproperty="junit.failures"> <formatter type="xml"/> <fileset dir="${testdir1}"> <include name="**/*Test.java"/> </fileset> <fileset dir="${testdir2}"> <include name="**/*Test.java"/> </fileset> </batchtest> </junit> </target> <target name="run-tests" depends="init,compile-tests,execute-tests"> <junitreport todir="${reports}"> <fileset dir="${reports}/raw/"> <include name="TEST-*.xml"/> </fileset> <report format="noframes" todir="${reports}\html\"/> </junitreport> </target> <target name="with.clover"> <clover-setup initString="${clover.db}"/> </target> <target name="clover.report"> <clover-report initstring="${clover.db}"> <current outfile="${src}/target/site/clover/clover.xml" /> <current outfile="${src}/target/site/clover"> <format type="html"/> </current> </clover-report> </target> <target name="all" depends="run-tests"> <fail if="junit.errors" message="Unit Test Errors Found"/> <fail if="junit.failures" message="Unit Test Failures Found"/> </target> </project> This is the log i see when I execute, any help would be appreciated. I have been researching this, but could not figure out yet (sad) Buildfile: C:\<path to src>\build_junit.xml with.clover: [clover-setup] Clover Version 3.3.0, built on March 31 2014 (build-912) [clover-setup] Loaded from: C:\<path to>\build\clover\clover.jar [clover-setup] Clover: Commercial License registered to GE Global Research. [clover-setup] Clover is enabled with initstring 'C:\<path to src>\target\clover\database\clover.db' init: [mkdir] Created dir: C:\<path to src>\reports [mkdir] Created dir: C:\<path to src>\reports\raw [mkdir] Created dir: C:\<path to src>\reports\html [mkdir] Created dir: C:\<path to src>\test [mkdir] Created dir: C:\<path to src>\tests [mkdir] Created dir: C:\<path to src>\test\Config compile-tests: [javac] C:\<path to src>\build_junit.xml:51: warning: 'i ncludeantruntime' was not set, defaulting to build.sysclasspath=last; set to fal se for repeatable builds [javac] Compiling 500 source files to C:\<path to src>\t est\tests [clover] Clover Version 3.3.0, built on March 31 2014 (build-912) [clover] Loaded from: C:\<path>\build\clover\clover.jar [clover] Clover: Commercial License registered to xyz. [clover] Updating existing database at 'C:\<path to src>\ target\clover\database\clover.db'. [clover] Processing files at 1.6 source level. [clover] Clover all over. Instrumented 500 files (82 packages). [clover] 198 test methods detected. [clover] Elapsed time = 13.356 secs. (37.436 files/sec, 5,059.299 srclines/se c)

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 22, 2014

There may be several reasons of no code coverage, but I can't tell which one exactly without seeing the whole build log. I suspect that you're running original code instead of the instrumented one. Into which directory do you put instrumented classes? Is it the same directory which is scanned by <junit> task? Feel free to raise a support ticket at support.atlassian.com - I can analyze it further.

Padma G November 24, 2014

Thank you - I have created ticket - https://support.atlassian.com/servicedesk/customer/portal/13/CLV-6157 . junit put the classes in <src>\tests - so when I this command - ant -buildfile build_junit.xml with.clover run-tests clover.report - does it not put instrumented classes in the same directory? clover related files get created in <src>/target - the reports etc. I have attached the build file and complete log in the ticket. Please advise.

Marek Parfianowicz
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
December 3, 2014

ANSWER: Lack of code coverage was caused by a fact that <junit>'s class path contained both classes instrumented by Clover and the original classes (which were packed inside JAR files). As <junit>'s class path looked like this: <classpath> <path refid="junit.classpath"/> <!-- non-instrumented code --> <pathelement path="${testsrc}/tests"/> <!-- instrumented code --> </classpath> non-instrumented code was picked by class loaders as it was first in a class path. Changing the order of entries: <classpath> <pathelement path="${testsrc}/tests"/> <!-- instrumented code --> <path refid="junit.classpath"/> <!-- non-instrumented code --> </classpath> solved the problem.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events