JPz'log Coin Coin and Plop da Plop

19Jan/090

Code coverage reports made easy

Test-driven development is a wonderful thing that really boosts your productivity... unless of course you fall into some kind of extreme dogma (ok, you should avoid static methods, but claiming that they can't be tested properly is a fallacy).

Actually this post is not meant to advocate TDD.
Others do it way better than I anyway, and this is a topic that has been reharshed, and reharshed, and... reharshed right? :-)

So starting from here I assume that you are using TDD in your projects with care and intelligence. And if you're not, try TDD for real to understand their benefits and drawbacks.

Keeping the bar gteen is fine, but we often forget to properly track code coverage. Indeed, there is no real point in keeping the bar green if your tests cover 10% of the code that you have actually written!

Lots of tools exist to fill this need. One that caught my eye recently is Cobertura. It's a very good one, distributed under the GPL (and since you are probably not modifying it at all, the license should not be an issue).

Cobertura tracks down code coverage metrics: line coverage, branch coverage and complexity. It generates Javadoc-style HTML reports, and for each class, you get the source code highlighted with useful informations:

  • the number of times each line / branch was accessed
  • lines and branches that have not been accessed appear in red

Cobertura is easy to plug into Maven:

You can then run:

mvn cobertura:cobertura

and get the reports in target/site/cobertura

Easy isn't it?

Cobertura can vastly improve your tests suites if you run it from time to time to spot the areas that have not be caught by your test cases.

Of course don't try to target 100% of code coverage (that's stupid and silly, really): there are always some parts of your code that don't need testing. An easy example is a trivial getter of setter.

Share this post:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • DZone
  • Live
  • Netvibes
  • StumbleUpon
  • Technorati
  • FriendFeed
  • Wikio
  • Twitter
  • Identi.ca
  • Reddit
  • RSS
  • Slashdot

Related posts:

  1. Start in Git, push to Subversion then work with git-svn
  2. Digne du Daily WTF
  3. Git branches to handle contributor patches
  4. Howto: fork a Subversion project with Git
  5. Making a stable release from a Subversion trunk… with Git

Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


No trackbacks yet.

JPz'log is Digg proof thanks to caching by WP Super Cache