Catching up with coverage... and finding some bugs

Yesterday I noticed again that on one of my projects the test coverage
is slipping. Now test coverage isn't everything, and hey, we're not that
bad since lots of projects have no tests at all... but still I'd prefer
the coverage to be at 100%. So in a moment of not wanting to touch any
new tasks ("just give me something small to hax0r, a few lines"), I looked at
the coverage report, trying to fill a few small holes.

A few of those small one or two line holes were quickly filled. A
one line function without a test? Tchak, done! Some others were more
mysterious. And then there was one that should have been easy to plug,
but it evaded me. An if x not in some_list that should raise an
exception was not covered. But once I wrote a test with assertRaises,
that part of the code was not reached any more. You start to test for
something and then it disappears? That would be a new one.

It took me some gazing at the code to discover that a (hidden) similar
check a few lines above was already raising the exception. So that
part of the code was essentially duplicated and useless. That's the morale of the
story: Bringing the test coverage back to 100% might not make your code
foolproof, but sometimes it just makes you look at the code again and
spot a bug here and there.

Life in Athens (Greece) for a foreigner from the other side of the mountains.
And with an interest in digital life and the feeling of change in a big city.
Multilingual English - German - Greek.Main blog page