Lec 15
Lec 15
Lec 15
Lecture 15
Main WBT Techniques
• Statement Coverage
• Branch Coverage
• Path Coverage
Path Coverage
• Path coverage tests all the paths of the program.
• To simplify these let’s consider below flowchart of the pseudo code we have:
• Now to ensure maximum coverage, we would require 4 test cases.
• How? Simply – there are 2 decision statements, so for each decision
statement, we would need two branches to test. One for true and the
other for the false condition. So for 2 decision statements, we would
require 2 test cases to test the true side and 2 test cases to test the
false side, which makes a total of 4 test cases.
• In order to have the full coverage, we would need following test
cases:
• TestCase_01: A=50, B=60
• TestCase_02: A=55, B=40
• TestCase_03: A=40, B=65
• TestCase_04: A=30, B=30
Loop in the path
Can we cover all the possible paths?
Basis Path Testing
• Any software program includes multiple entry and exit points Testing
each of these points is challenging and time consuming.
• V(G) = 9 – 8 + 2 = 3
• e=9
• n=8
Predicate Method
• V(G) = P + 1
• V(G) = 2 + 1 = 3
• P=2
Number of Regions
• V(G) = 3
• Basis Path Coverage
There are few conditional statements
that are executed depending on what
condition it suffice. Here there are 3
paths or condition that need to be
tested to get the output.
• Path 1: 1,2,3,5,6, 7
• Path 2: 1,2,4,5,6, 7
• Path 3: 1, 6, 7
Why Cyclomatic Complexity?
• To check if the program is testable?
• To check if the program easy to understand?
• To check if the program easy to modify?
Example 1
GET(A); GET(B);
if A > 15 then
if B < 10 then
B := A + 5;
else
B := A - 5;
end if
else
A := B + 5;
end if;
end XYZ;
Example 2
IF A = 10 THEN
IF B > C THEN
A=B
ELSE
A=C
ENDIF
ENDIF
Solution for Example 2
• V(G) = E – N + 2
• 8-7+2=3
• Rule of thumb:
• Begin restructuring your code with the component with highest V(G)