What are the benefits of Block Testing?

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.

• 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
Commented May 25, 2011 at 16:23

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.

• +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." Commented May 25, 2011 at 20:32
• How can you argue with the Author :-) Commented May 26, 2011 at 8:13
• This is a new type of testing for me and thanks for bringing it to light Commented Dec 13, 2016 at 11:40