My other blog (in Hungarian) merhetetlen.blogspot.com

Friday 2 September 2011

Coverage to rule them all

There are two things in my mind. Lets start with thing B:

I can't say it was love at first sight... I knew immediately that she is something new and good and effective, but she was so strange and uncommon... so I give up after a few date. But a few weeks ago I have to meet with her again. Mizz JaCoCo... Previously I always with Cobertura. She is simple, easy, a little mysterious, but to be honest, really hard to use for what I had to...

To understand what the situation was I have to introduce the other party member: Sonar. It is unbelievable, free and knows a lot. But it is tied up with JaCoCo if you have to store integration and unit test coverage for a project. And we had to. So I've downloaded JaCoCo again and read a few examples on sonar page and on its documentation site. Maybe I 'm stupid, put something was wrong with them. I can't make it work.... I read it again and again and again and I realized that I was stupid. I was following the post too blindly. JaCoCo is an on-the-fly instrumentation tool. It instruments anything in the JVM. Why the hack they give the bloody -javaagent to the failsafe plugin? In every example it was there, but it is nonsense. And I realized it is meaningless (not everytime, but get over it), I should have passed it the cargo container... (now I know, if I did not fork the container, and use another maven process to gather the coverage I could have reached the same result), but I can't understand why they hide this little information from the readers, or am I the one-and-only idiot who can't find out this immediately? (I know, I know...)

But after the revelation I could create a simple maven build to:
1.  compile the project
2. instrument it with cobertura
3. run unit tests against it
4. package the application without cobertura
5. deploy it to cargo (as soon as the Jetty plugin can be forked it can be used as well)
6. run the integration tests against it
7. gather the coverage
8. install it to local repo (end of the install phase, or we could run to verify phase... who cares :) )
and run sonar:sonar to:
1. analyse coverage files
2. analyse with findbugs and so on...
3. put the results to Sonar

And it was eeeaaasssy.
So beware! Don't be stupid! Give JaCoCo to the container...

No comments:

Post a Comment