When you try to generate a Clover report you see:
- less coverage than expected
- or no coverage
- or even report is not created at all and a message like this is printed:
[clover-report] Processed 0 recording files in 12ms (- per recording) [clover-report] Processed 0 per-test recording files in 0ms (- per recording) [clover-report] No coverage recordings found. No report will be generated.
Despite the fact that you see global coverage recording files in a directory where Clover database is located.
When you enable Clover debug logging (ant -d / mvn -X) you see a message like:
[clover-report] Ignoring coverage recording CoverageRecordingTranscript.FromStream[header=Header[ dbVersion=1322688610511, writeTimeStamp=1323291710342, format=0], coverageSum=171, hitCounts.length=1751667] because no FileInfo supports its coverage range
Whenever Clover instruments a source file, it records its time stamp in the Clover database. It's not a file modification time , but a time when instrumentation of the file was performed. As you can modify and instrument the same file multiple times, Clover will record history of this file as well, tracking all build sessions in which it was instrumented. When you compile and next run an instrumented class, it will connect to an instance of Clover's coverage recorder associated with a proper instrumentation session (in a sample above it's dbVersion=1322688610511). Coverage recorder will write a global coverage file to disk with current system time as its time stamp (in a sample above writeTimeStamp=1323291710342).
During report generation, Clover checks dbVersion property of global coverage recording files discarding those which are outdated (comparing dbVersion against a list of instrumentation sessions registered in a Clover database).
This is a normal Clover behaviour, however it may cause troubles in case when Clover database and coverage recording files are not managed correctly.
Imagine a following, faulty, scenario:
- application code is instrumented, clover.db file is created
- clover.db is deleted
- test code is instrumented, new clover.db file is created
- tests are launched
- coverage recorder for application classes writes a global recording file
- another coverage recorder for test classes writes another global recording file
- report is generated
- because of the fact that the clover.db was deleted in step 2, a global recording file with a coverage for application classes is discarded
- as a result, coverage for application code is missing in a report
OK. Clover records file modification time as well, but it's being used for different purposes.
Check whether your build script does not accidentally delete Clover's database in a middle of a build. Look for "Creating new database at <path/to/clover.db>" vs "Updating existing database at <path/to/clover.db>" messages in a build log.
Check if your build does not use outdated database for reporting (fetching a shared artefact from old build on continuous integration server, for instance).
Check if you delete old Clover database and coverage recording files between builds (unless you perform an incremental compilation).
In case when build is performed on several machines - check if system time is set correctly on all of them.
Check if you don't modify source files after they were compiled and coverage was recorded and before the report is generated, which could potentially trigger recompilation (imagine a target dependency like: "report -> test -> compile" where the "compile" target removes clover.db).