I installed this module about 2 months ago and, despite articles like How to Misuse Code Coverage, that don't recommend trying to achieve 100% coverage, I thought I have a bash at it, and see what I would learn.
It wasn't easy to get to 100% coverage, especially when different platforms are taken into consideration. But I did learn a lot. And I found numberous issues with what I had (before the exercise) thought was solid, well designed and tested code (there was already >700 test cases across the 2 libraries).
In no particular order, things I found were
- where parts of my API were hard to use
- inconsistencies in the usage of the API or its return values
- that even with 100% coverage, there are still bugs - I fixed one just yesterday
- it highlighted bad implementation and design decision
- highlighted several redundant areas - along the lines of 'if these preconditions are met, then it is impossible to reach this part of the code'
- bugs continued to be found right up to the very end of generating coverage test cases, which was surprising - I thought that the last lot would be just to prove expected behaviour
- bugs fixes that broke legacy behaviour were quickly identified. This allowed informed decisions like do we try a non-breaking fix or fix the code expecting the broken behaviour
- most coverage tests were to test abnormal execution paths - and as such they proved most bug ridden - probably because of the mind-set '...but that'll probably never happen', which meant we weren't being as rigorous as we should have been
The lessons I learnt (or were reinforced) were
- testing is good, more testing is better, immense testing is great
- even if everything is tested, it might still be wrong
- fixing the remaining bugs as they arise is made ridiculously easy in most cases, because it is so well tested. Fixes that break existing behaviour are highlighted as test failures - without test cases you might never know
- remaining bugs seem like they will be mostly limited to data scenarios you haven't accommodated for. Our last one was for multiple CR (\r)'s in the data stream - we weren't expecting that
Whilst I wouldn't state that getting 100% coverage is required by everyone, just the exercise of attempting it can be revealing.
We've just had one of our developers finish a new library, and that currently has 92% coverage. We plan to get the rest of us familiar with the new API by having each developer extend the coverage tests by 1-2% each. Eventually everyone will have had to write a little code using the API, which is the best way to learn it.
use brain;