Coverage recording files are not being generated, coverage results in 0%

All my code coverage reports show 0% coverage.  After some debugging, I see that no recording files are being generated after instrumenting, compiling, and running tests.  The only file I see is the clover-coverage.db file in my module directories but no clover-coverage.db#####_#### files.  

The report generation succeeds and generates the html reports but all of them show 0% coverage.

The order of steps I'm taking is:

<clover-setup initstring="${location_of_db}" flushpolicy="threaded" flushinterval="100000"/>

compileJava

compileTests

runTests

generateReport

What am I doing wrong?  How can I get the recording files to generate? Would greatly appreciate any help.

2 answers

This widget could not be displayed.

May I ask you to attach a build log, please? It's hard to tell what could be the root cause, without knowing more details about the build.

 

The most common causes of lack of code coverage are:

1) Source files were not instrumented by Clover

 - did you call "clean" in your workspace? if not then source files may have been already compiled in previous builds (without Clover) and thus <javac> did not compile anything,

 - did you call <clover-setup> before <javac>? check order of your targets in a build log,

 - do you call <ant> or <antcall> tasks in your bulid? if yes, then ensure that inheritRefs=true attribute is set; otherwise, things set by <clover-setup> will be lost in sub-module calls and <javac> will be called without Clover

 

2) Clover database cannot be found at runtime

 - this usually occurs when a relative path is used in <clover-setup initstring=""> and tests/application are running in a different working directory (deployed to Tomcat, for instance)

 - either use absolute path in initstring to solve a problem of different working directory or

 - use -Dclover.initstring JVM property at runtime pointing to database location

 

3) Clover did not flush coverage data to disk

 - this can happen when the default flush policy is being used - in such case coverage recording files are written to disk only once - at JVM shutdown

 - which means that if JVM is killed (kill -9) then no coverage will be available

 - which also means that if JVM is not stopped after tests (a Tomcat server running permanently, for instance) then no coverage will be available

 - which also may happen if you have <junit> with fork="false" - unit tests are running in the same JVM and coverage is not written until build is finished; which means that report generation may occur for no coverage data

 

solutions:

 - use "threaded" or "interval" flush policy

 - use <junit> with fork=true

 - do not use 'kill -9' to stop JVM

 

Cheers
Marek

This widget could not be displayed.

Hi Marek,

1) Yes I do a distclean and call clover-clean and <clover-setup> before compiling.  I call <clover-setup> in a loop with the initstring set to each module directory so that each module has a clover-coverage.db within it.  

        <clover-setup initstring="${module.coverage.data.dir}"/clover-coverage.db" flushpolicy="threaded" flushinterval="100000">

This gives me:

${core.home}/modules/moduleA/clover-coverage.db

${core.home}/modules/moduleB/clover-coverage.db

${core.home}/modules/moduleC/clover-coverage.db

....

${core.home}/modules/moduleZ/clover-coverage.db

 

Here's a snippet of the log during <clover-setup>

[INFO]
[INFO] --- maven-clover2-plugin:3.1.12:setup (clover-instrument) @ gen ---
[INFO] Clover Version 3.1.12, built on June 27 2013 (build-899)
[INFO] Loaded from: {core.home}/com/cenqua/clover/clover/3.1.12/clover-3.1.12.jar
[INFO] Clover: Commercial License registered to
[INFO] Creating new database at '{module.coverage.data.dir}/modules/gen/clover-coverage.db'.
[INFO] Processing files at 1.6 source level.
[INFO] Clover all over. Instrumented 48 files (6 packages).
[INFO] Elapsed time = 0.532 secs. (90.226 files/sec, 24,943.609 srclines/sec)-
[INFO] Performing incremental build
[INFO]
[INFO] Incremental build configuration change detected, performing full build
[INFO] Compiling 48 sources to {core.home}/gen/target/classes
[INFO] Clover all over. Instrumented 1019 files (7 packages).
[INFO] Elapsed time = 8.346 secs. (122.094 files/sec, 16,982.027 srclines/sec)
[INFO] --- udd-gen-maven-plugin:1.0.0.generation:generate-pljava (pljava) @ udd-constants ---
[INFO] Incremental build configuration change detected, performing full build
reading SqlTypes.sql
reading GeneratedSqlTypes.sql
[INFO]
[INFO] --- maven-clover2-plugin:3.1.12:setup (clover-instrument) @ udd-constants ---
[INFO] Clover Version 3.1.12, built on June 27 2013 (build-899)
[INFO] Loaded from: {core.home}/com/cenqua/clover/clover/3.1.12/clover-3.1.12.jar
[INFO] Clover: Commercial License registered to 
[INFO] Creating new database at '{module.coverage.data.dir}/modules/udd-constants/clover-coverage.db'.
[INFO] Processing files at 1.6 source level.
[INFO] Clover all over. Instrumented 3305 files (6 packages).
[INFO] Elapsed time = 5.419 secs. (609.891 files/sec, 31,167.928 srclines/sec)

After I compile java, I compile the tests.  Then I run an entire suite of tests from all the modules.  Since this takes about 17 hours, I use the flushpolicy to make sure it's getting written to disk.  After the tests are complete, I generate the report, and see they're all 0.

 

I will check that we use inheritRefs=true in all the ant calls in my build.  

 

2) Our test code exists in the same main directory but under a different folder called "test":

moduleA

     .../java/src

    .../test/

Is there an exception I should search for to check that it's able to find the db at runtime?

3) I'm using flushpolicy=threaded with flushinterval="100000" since we don't shut down the 

 

Please let me know if you need more info or I've left anything out.  Our log file is quite large due to the number of tests executed so hope I got you the information you asked for.  Thanks Marek!

 

I'd like to clarify few things: 1) In the build log I see: [INFO] Creating new database at '{module.coverage.data.dir}/modules/gen/clover-coverage.db'. As you can see, a path contains {module.coverage.data.dir} which is rather incorrect. Unless you've obfuscated the original log? 2) On the one hand I see that your build log is based on Maven: [INFO] --- maven-clover2-plugin:3.1.12:setup (clover-instrument) @ udd-constants --- but on the other hand you wrote that you're using Ant. Which build system do you use? Both? If yes, then how do you call Clover-for-Ant from Maven? 3) You wrote that: Our test code exists in the same main directory but under a different folder called "test": How did you configure this different source root?

PS: feel free to create a ticket at http://support.atlassian.com and attach build files and logs - having complete view of your project setup can speed up my investigation.

Thanks Marek for the response! Yes, I obfuscated the original log and we're using both maven and ant at the moment. I will create a ticket and attach the entire build log.

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

139 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you