Should error cases be tested, too?
Is it possible to get to 100% testing code coverage? And what does that mean?
Let me explain by continuing to use the passing grades code we were exploring in the previous section. Here is the test again:
TEST("Test passing grades")
{
bool result = isPassingGrade(0);
CONFIRM_FALSE(result);
result = isPassingGrade(100);
CONFIRM_TRUE(result);
}
Right now, this test does cover 100% of the function under test. That means that all of the code inside the isPassingGrade
function is being run by at least one test. I know, the isPassingGrade
function is a simple function with a single line of code that always returns true. It looks like this:
bool isPassingGrade (int value)
{
return true;
}
With a function this simple, just calling it from within a test will make sure that all of the code is covered or run. As it...