There has been a marked surge of interest in coverage testing recently, and Perl has excellent support for this
aspect via Paul Johnson's excellent
Devel::Cover.
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.