Sample Questions and Approach to Solve them

Critical chapter of Foundation syllabus is Test design Technique. So, i want to start from there.

Calculate Statement, Branch/Decision and Path coverage for code below ?

Read X,Y;
If (X>Y)
Then print" X is greater";
End If
If (X+Y > 100)
Then print "large";
   If (Y == 50)
    Then print "X should be more than 50";
   End If
End If

Answer: Lets draw flow diagram for this code which will help us solve the problem easily.



Statement Coverage:


Now, lets calculate statement coverage, find out the shortest path covering all nodes. If we consider exam above. Then Statement Coverage = 1A- 2C- 3D -4F -5G-6I-7J-K So, traversing in one path all the nodes are covered. Hence statement coverage in this case is 1.


Branch Coverage:


To calculate Branch/decision coverage we need to find out minimum number of paths covering all the edges. In this case, with path 1A-2C-3D -4F -5G-6I-7J-K maximum number of edges can be covered however edges B, E and H are left out. Lets try to cover them 1A-2B-DE-K. We are still missing edge H hence we should cover that as well. 1A-2C-3D-4F-5G-6H-J-K. So, in this case decision coverage is 3

Path Coverage:

Path coverage is always covers all possible paths from start to end. In our case all possible paths are:

1A- 2C- 3D -4F -5G-6I-7J-K
1A-2C-3D-4F-5G-6H-J-K
1A- 2B- 3D -4F -5G-6I-7J-K
1A-2B-3D-4F-5G-6H-J-K
1A-2B-DE-K

So, path coverage is 5

Always remember below statements:
  • 100% PC = 100% SC
  • 100% BC/DC = 100% SC
  • 100% PC = 100% BC/DC
In my next post i will talk about "State Transition and Switch Coverage" you can read more about this post here

Comments

Post a Comment

Please leave your comments here