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.
- Anybody can ask a question
- Anybody can answer
- The best answers are voted up and rise to the top
The difference between statement coverage and block coverage is in the math. Take this example:
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.