digiarnie
digiarnie

Reputation: 23355

Performing code coverage using Clover on a Play! Framework Application using Ant

I'm writing an Ant script to do some additional checks on my Play! Framework Application.

Currently, I am executing my tests from my Ant script by simply making an exec call to "play auto-test".

    <exec executable="${play.dir}/play.bat">
        <arg line="auto-test"/>
    </exec>

Would anyone know how to integrate Clover into a Play test suite? Obviously I am not tied to having to run my tests using the above.

I also tried writing the Ant script using the traditional way of executing JUnit tests (i.e. using Ant's junit target) and I got two problems:

So if I were to go down the junit route, I would need to know how to execute all my tests so that they can run one after another successfully (it works when using the Play way of running play auto-test) and I would need to know why Clover does not seem to pick up lines of code touched by Play tests.

(I know there is a Cobertura module for Play, however, I find that Clover does a better job telling me an accurate coverage figure)

Update: Unfortunately I am unable to replicate the exact error I was getting before as I have run into compilation issues when I try and compile things manually. I've started to use the Secure module and it only contains Java source files. So in my Ant script, I call play precompile which produces the byte code for the Secure module (as well as everything else in the system including my code). So now when I try and compile my app code using Clover, I think the compiler gets into a bit of a tangle as I have two versions of my classes - one produced by the precompile command (non-clover) and one produced by my own ant compilation (with clover):

[javac] C:\projects\testproject\out\clover\classes\clover8583527041716431332.tmp\model\HouseTest.java:45: incompatible types
[javac] found   : play.db.jpa.JPABase
[javac] required: models.House
[javac]         __CLR2_5_115y15ygoxiz3dv.R.inc(1527);House found = House.findById(id);

So I essentially have two problems now:

Update #2: It turns out that the error I got was due to the findById call required a cast from JPABase to House (not that the IDE or play seemed to care about it). So after I went in and put a cast for all of play's "find*" methods, I actually got JUnit and Clover reports! However... I am now getting two kinds of errors:

I have a feeling there is one magic fix that will resolve both of my issues however I am unsure what that magic fix is.

Upvotes: 12

Views: 1483

Answers (1)

Ron
Ron

Reputation: 682

Clover does source level instrumentation, so it needs source code available. Everything you do before activating clover that generates bytecode will not be "clovered".

Clover for ant intercepts ant-compiler calls, so if you do a <clover-setup/> before any other compilation tasks in your ant script, everything sould be instrumented by clover.

You can execute the resulting compiled code in any way you want, e.g. executing from script or from junit, it does not matter, as long as the code is instrumented (and of course clover.jar is available in the classpath). Clover hard-codes the location of the clover-database into the instrumented code, so you do not have to specify anything when executing.

It would really help, if you could outline how you are using clover, and you could also do a recheck at clover documentation at http://confluence.atlassian.com/display/CLOVER/1.+QuickStart+Guide.

Upvotes: 4

Related Questions