img
Question:
Published on: 3 December, 2024

Difference between Statement coverage and Branch coverage.

Answer:

Statement coverage vs. Branch coverage:

The coverage-based testing is frequently used to check the quality of testing achieved by a test suite. It is hard to manually design a test suite to achieve a specific coverage for a non-trivial program.

Statement coverage:

The statement coverage strategy aims to design test cases so as to execute every statement in a program at least once. The principle idea governing the statement coverage strategy is that unless a statement is executed, there is no way to determine whether an error exists in that statement. It can be however be pointed out that a weakness of the statement-coverage is that executing a statement once and observing that it behaves properly for one input value is no guarantee that it will behave correctly for all input values.

         int ComputeGCD(x,y)

         int x,y;

         {

          while(x!=y)

         {

          if(x>y) then

          x=x-y;

          else y=y-x;

          }

          Return x;

To design the test cases for the statement coverage, the conditional expression of the while statement needs to be made true and the conditional expression of the if statement needs to made both true and false. The test sets are {(x=3,y=3),(x=4,y=3),(x=3,y=4)}.

Branch coverage:

A test suite satisfies branch coverage, if it makes each branch condition in the program to assume true and false values in turn. It is also known as edge testing, since in this testing scheme, each edge of a program’s control flow graph is traversed at least once. It is stronger than statement coverage based testing.

          int ComputeGCD(x,y)

          int x,y;

          {

           while(x!=y)

          {

          if(x>y) then

           x=x-y;

          else y=y-x;

          }

 

The test sets {(x=3,y=3),(x=3,y=2),(x=4,y=3),(x=3,y=4)} can achieves branch coverage.

 

Random questions