October 02, 2010

If you have written automated tests for computer programs, you are very likely to be familiar with code coverage. Almost everyone agrees that 100% code coverage from your tests doesn't mean that your code doesn't have any bugs. I have been told this by experts, and I accepted it as such all this while. Suddenly a few days back I could come up with an example where the test coverage is indeed 100%, and yet one bug goes unnoticed.

This example is an extremely simple case (you can even call it stupid) and the bug is on your face. But in real systems bugs may not be so apparent. Here is the code we are testing: