Why Test Coverage?

If you haven’t tried to do something yourself, you will never be able to appreciate its advantages or disadvantages because there’s only so much you can learn from theory. So do whatever you talked about doing all the time …

Case in point: test coverage. We all know we should a) design for testing and b) write those tests.

Have you ever written a new method, checked if your tests at least executed that method, exclaimed a happy “Yes!” and then simply extended your test input, have your tests fail, fixed a little something and saw you were back on track with no worries about undiscovered side effects?

I just installed Sonar the other day and even my best project only has a coverage of about 70% of lines. But there is a world of difference between those 2% and 70% projects in terms of cost developing new features.

I agree test coverage may look expensive from the outside. Once you have it however, your future development becomes a lot cheaper.

Yes it may be faster – in the beginning – to rely on manual tests by the developers but sooner or later you will reach the tipping point where those manual tests fail to discover a few major bugs before they cause trouble.

Automated tests do a lot of good things for you. They

  • help discover bugs early
  • are a method of coding your specification
  • discover unintended side effects
  • force your developers to design for testing
  • improve the overall quality of code by forcing developer’s to think more about the design
  • allow newcomers to the project to code faster
  • allow developers to do more risky refactorings (to improve code quality)
  • are fun to code once you get started
  • reduce developers’ stress by giving them a safety net

So even if it looks more expensive to allow (or force) your developers to write good quality code, a good long term strategy would be to invest the time needed.

Just my thoughts on writing a new method and being able to fix all the little issues that occurred immediately because the tests failed at first.

PS: yes it’s 2012 and we should have moved beyond the need for this rant by this …

This entry was posted in development. Bookmark the permalink.

Comments are closed.