Coverage analysis can only tell you how the code that exists has been exercised. It cannot tell you how code that ought to exist would have been executed. Consider the following:
error_code = FunctionCall();
// returns kFatalError, kRecoverableError, or kSuccess
if (error_code == kFatalError) {
// handle fatal error, exit
} else {
// assume call succeeded
}
This code is only handling two out of the three possible return values (a bug!). It is missing code to do error recovery when kRecoverableError is returned. With tests that generate only the values kFatalError and kSuccess, you will see 100% coverage. The test case for kRecoverableError does not increase coverage, and appears “redundant” for coverage purposes, but it exposes the bug!
nice explanation that code coverage is not the same as path coverage
ReplyDeleteAmazing example on code coverage. But looks as if better said than done. Really wish if we lived in a perfect world. Blogging initiatives like the current one keeps the spirits live. Good guys.
ReplyDeletegreat explanation, besides code coverage it also made me many more things to understand.
ReplyDeleteSachin
great explanation, besides code coverage it also made me understand many more things.
ReplyDeleteSachin