Take the 2-minute tour ×
Software Quality Assurance & Testing Stack Exchange is a question and answer site for software quality control experts, automation engineers, and software testers. It's 100% free, no registration required.

I came across the term "Block Testing" in the book "How We Test At Microsoft". I can't really see how this should be applied, should you do this instead of statement testing? From what I understand if you do statement testing then you essentially have done block testing.

share|improve this question
1  
Are you referring to block coverage ? I'm guessing from context (and as someone quite familiar with the book) that's the case, but if not, point me to a page number and I'll see what I can do to clarify. Do you have a more specific question? –  Alan May 25 '11 at 16:23
add comment

1 Answer

up vote 9 down vote accepted

The difference between statement coverage and block coverage is in the math. Take this example:

if (val == true)
{
  DoThis();
  DoThat();
  DoTheOtherThing();
}
else
{
  DoSomethingElse();
}

In that example, there are two blocks of code (the true side of the statement and the false side). If the first statement (DoThis();) of the true block executes, then the following two lines will execute (assuming no exceptions).

The math behind block coverage (for those who care about that sort of thing) is concerned with how many blocks have executed. There are two blocks in this code sample, so testing one block (e.g. the true side of the if condition) would give you 50% block coverage.

The math behind statement coverage is concerned with how many of the total statements have been covered. The true side of the if condition has 3 of the 4 statements in this excerpt, so writing one test that covers the true case has 75% statement coverage.

In the end, the math doesn't really matter. The reason to measure coverage isn't to produce a number - it's to help you discover what areas of the code are not covered by your testing so you can determine if more testing is needed. In other words, coverage testing is a method of discovering new tests.

share|improve this answer
2  
+1 for a wonderfully clear explanation and an additional +1 if I could vote it up again for these great sentences that should be carved in stone: "In the end, the math doesn't really matter. The reason to measure coverage isn't to produce a number - it's to help you discover what areas of the code are not covered by your testing so you can determine if more testing is needed. In other words, coverage testing is a method of discovering new tests." –  Justin May 25 '11 at 20:32
    
How can you argue with the Author :-) –  Bruce McLeod May 26 '11 at 8:13
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.