How to Calculate Statement Coverage

Share and Enjoy !

Statement Coverage a metric which gives you an idea if every statement inside the code is executed at least once. This is a white box technique.
As the objective says it is the lowest possible test cases that will cover all the statements at least once.
Let us take a piece of code:
C = A – B
C = A + B
Read D
IF C = D Then
Print “Error”
 statement coverage
here 3 statements needs to be covered.Our objective is to find out what is the minimum number of test cases that is possible value of A,B,C,D will satisfies this….
lets take a case where A<B
A=40 and B=50,D=20
This values will execute statement –2 and will skip statement-1.In the very next if condition will fail and will not execute Statement-3…But this condition will satisfy Statement-2 only.
Now twist the input a little bit.
Here i will consider A>B
These values will surely satisfy the Statement –1 and in the second case will satisfy Statement-3…But again this will not execute –Statement-2.
So the conclusion is Minimum number of tetstcases required to execute each statemnt once is –2.
Hence the Statement Coverage-2 
This is a very small piece of code where we found out the statement coverage…but if this is a very large lines of code then manually finding out of this value is really tough.
There is tool called Profiler that will indicate the no of statement executed and by doing trials we will be able to find out the Statement coverage.

See also  Common Testing Processes of an Organization

Share and Enjoy !

Leave a Reply

Your email address will not be published. Required fields are marked *