2

What is the different between Unit Testing and Block Testing? They both seem to cover the same section of code. I'm writing a Test Approach report. The PM wants answers to these categories.

1

4 Answers 4

2

I don't think block testing is a commonly accepted term. What you are probably referring to is block coverage.

Unit testing is a TYPE of testing, where the smallest 'units' in an application are tested in isolation. This often means testing individual methods in a class, with mocked or stubbed external dependencies.

One level higher than a unit testing is integration testing, which is meant to test the interaction between different groups of code together. This can be relatively shallow by just testing a combination of several classes, or it can be broader in the sense that you store data in a running database.

In any type of test, you might be interested in how much of a certain section of code is covered by any type of test. The simplest form is line coverage where you measure the percentage of code lines that have been executed after all tests were run. This example here shows how block coverage works:

https://stackoverflow.com/questions/35844439/what-is-the-difference-between-block-coverage-and-branch-coverage

You can measure the coverage for both unit and integration tests.

2

This question is kind of like asking "what's the difference between apples and red delicious?" They aren't mutually exclusive. :)

Unit testing is a broad category of tests that are generally short, fast, and isolated (the code being tested has few or no dependencies, such as an individual method).

Block coverage is a metric you might use to evaluate your overall unit test coverage, or a technique you might use to help you increase your coverage when writing new unit tests. As I commented above, this answer to a question about block coverage gives a very good summary of what block coverage is and how it differs from statement coverage, which is a more, well, apples to apples, comparison.

1

Unit Testing is testing of unit/module of the code. A project may consist of various units/modules. Testing the units in isolation to check whether they work fine is known as Unit Testing. Unit Testing is generally done by developers, but not necessarily the developer who wrote the modules/units.

A Block Testing is testing done on a block of code. For example, testing a sub-class of a higher class, or testing some lines of code work properly or not. Block testing is done by the developer of the code, as he/she may have a better understanding of the code written by them.

0

As you know, Unit Testing is often a simple assert statement for a specific line of code. (ie "b = 1 + 1; assert(b==2)").

Block Testing is often concerned about covering both sides of a conditional statement. For example, if your program has an if/else statement then testing the "if" block would be one half of the coverage and the "else" statement would be the other half. Bear in mind that block testing is not limited to if/else statements but could be applied to case statements, elseif statements, etc. Basically, block coverage testing is done to ensure that blocks of code aren't left untested by failing to test all paths of a conditional statement.

4
  • This answer is overly simplistic. Unit testing is much broader than asserts against specific lines of code (the example test would really only be useful if testing a compiler). You may be getting unit testing mixed up with statement coverage?
    – c32hedge
    May 22, 2018 at 16:45
  • Perhaps but the point that I make is that unit tests are the smallest in scale and that block testing covers a larger area (often to ensure that conditionals receive test coverage). May 22, 2018 at 18:16
  • That is inaccurate, though. Read mine and Pieter A's answers--there really isn't something called "Block Testing". Block coverage is useful as part of unit testing, it isn't something that's larger than unit tests. They're two different types of things, though, so attempting to compare them in that way is going to be confusing.
    – c32hedge
    May 22, 2018 at 18:28
  • OK. I believe I see your point. Block Coverage versus Block Testing. Block coverage is generally the term you hear. However, in QA I've learned to go with the flow when it comes the tiny nuances in test names. Is there a difference between a sad path test and a negative test? In my mind there are slight distinctions; however, these are often used interchangeably. May 22, 2018 at 18:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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