The Ghost Classes of Cobertura

We use Cobertura inside our continuous integration system and I have spent the last two hours trying to figure out why a couple value objects where showing 0% coverage because, you know, they actually had tests written for them. Because I just wrote the tests!

After some investigation, I discovered the packages of these objects were different — the classes I wrote the tests for were in the vo package and the classes that had no coverage were in the beans package. I looked a the Cobertura report for the vo package and — heck — I had 100% coverage!! And there were no beans package for this project. Things just got a whole lot weirder.

I poked and prodded and figured out what was happening. It turns out that these objects were once in the beans package, but then got renamed to vo (which is our standard package for business objects). However, whoever refactored the classes didn’t refactor the tests with them. So there were still tests in the beans package that called the classes in vo. But this confused Cobertura, because it (rightfully) thought that there should be test for the beans package.

Interestingly enough, the ghost classes still showed up after I delete the rogue tests from SVN. I had to manually go into our CI server and do an “ant clean” to stop JUnit and Cobertura from reporting on them.

Is this a bug in Cobertura? Kinda, technically, maybe. But it’s actually a problem with how this was refactored. If you refactor you objects to a new package, remember to move your tests as well!!

Leave a Reply

You must be logged in to post a comment.