Clover report shows coverage, but 0 tests run. Test classes not instrumented either

I have used the instructions at http://gradle.codehaus.org/Cookbook#Cookbook-usingClover to get clover to run from my gradle build. It runs without error, and when it is completed an html report is generated. It correctly shows the code coverage for the sub-project that I’ve set it up on, but it also shows that 0 tests were run with the message “No test results could be found. Please ensure that you have instrumented your unit tests correctly”.

I notice in the build script in the example I used only the main directory is instrumented, and not the test directory:

//instrument the source
            new File(cloverConvention.instrSrcDir).mkdirs()
            sourceSets.main.java.srcDirs.each {
                if (it.exists()) {
                    ant."clover-instr"(srcdir:it, destdir:cloverConvention.instrSrcDir)
                }
            }

I’m not exactly sure the best way to modify the script to instrument the test classes. Any suggestions?

Thanks! Dave

You should probably give the Gradle Clover plugin a shot. The plugin will prevent you from having to reimplement all the code mentioned on the Cookbook.

Hope that helps. Just shoot me a mail should you decide to go with the plugin and run into issues.

Unfortunately for me, anything that is distributed with an open source license has to go through a fairly length approval process at my company. We have approval for Gradle but not your plugin. I need to get this working by the end of the week, and approval takes 4-6 weeks. Red tape is fun!

OK, never mind then. :wink:

I guess your problem is the fact that you don’t instrument the sources before running your tests. If you didn’t do that yet put your instrumentation code into a doFirst closure:

test.doFirst {
   <your code above>
}

The example code runs instrumentation first on src/main but doesn’t on src/test. I modified it to try to instrument src/test as well, but it still isn’t making any difference. I see the instrumented test source under the build/instrTestSrc (where my script specifies for it to be created) so I think that’s working.

One thing I’ve noticed is that in the clover.xml file, I’m seeing the test classes show up under the element and not under the element. How does clover differentiate between between main classes and test classes? I thought it was based on the testng.xml file but my understanding of how all these parts work together is pretty weak.