100% Code Coverage – Achievement Unlocked

Patrick Smacchia, of NDepend fame, brings arguments for pushing for maximum code coverage. We all know that it’s a problem reaching  over the top to cover all the code. Patrick says 100% coverage will motivate you to keep it that way.

There is some truth in that. The broken window theory states that as well.

Properties are the best candidate for raising the coverage, although they don’t do anything. You get the coverage, but you spend the time.  By the way, some may argue that the tests are in place for when we’ll add logic to our tests. Isn’t that YAGNI?

So it comes down to the question – is it worth it? Well, you might give yourself a nice pat on the back. But in most cases, it’s time and effort that are better spent on adding value to the product. It’s a waste of company money if you don’t need it.

Quality is not objective. (By the way, so is good design). Good development is not about adding quality to your code. It’s about adding value to your product. Code coverage does not add quality. It lowers the cost of maintenance. And like everything, the law of diminishing returns works here as well. The last 15% will cost more than what you receive at the end.

Use you judgment, and write tests when it makes sense. Do it for lowering costs, not for an achievement.

Leave a Reply

%d bloggers like this: