BASIC PATH TESTING
INTRODUCTI
ON
A white box method
Developed by McCabe in 1976
A hybrid of path testing and branch testing methods.
Based on Cyclomatic complexity and uses control flow to
establish the path coverage criteria referencing the
book C.Berge, Graphs and Hypergraphs (G&HG).
CYCLOMATIC COMPLEXITY
Measures the number of linearly independent paths through a
program.
The higher the number the more complex the code.
The cyclomatic number v(G) of an (undirected) graph G (which
may have several disconnected components) is defined as:
v(G) = e - v + p
where e = number of edges, v = number of vertices, p = number
of connected components
BASIC PATH TESTING APPROACH
Step 1: Draw a control flow graph.
Step 2: Determine Cyclomatic complexity.
Step 3: Find a basis set of paths.
Step 4: Generate test cases for each path.
CONVERTING CODE TO
5 GRAPH
CODE FLOWCHART GRAPH
if expression1 then
T expr1 F
For a strongly connected
n1
statement2
? graph:
else statm2 statm3 n2 n3
statement3 Create a virtual edge
end if
statement4 statm4 n4
to connect the END node
switch expr1 1 expr1 3
case 1: ?
n1 to the BEGIN node
statement2 2
n2 n3 n4
case 2: statm2 statm3 statm4 In that case,
statm3
case 3: n5 V= e – n + 1
statm5
statm4
end switch
statm5
do
statm1 n1
statement1
while expr2 T expr2
end do n2
?
statement3 F
statm3 n3
Draw a control flow graph
Basic control flow graph structures:
DRAW A CONTROL FLOW
GRAPH
Arrows or edges represent flows of
control.
Circles or nodes represent actions.
Areas bounded by edges and nodes
are called regions.
A predicate node is a node
containing a condition.
DRAW A CONTROL FLOW
GRAPH
1: IF A = 100
2: THEN IF B >
C
3: THEN A = B
4: ELSEA= C
5: ENDIF
6: ENDIF
7: Print A
DETERMINE CYCLOMATIC COMPLEXITY
There are several methods:
1. Cyclomatic complexity = edges - nodes
+ 2p
2. Cyclomatic complexity= Number of
Predicate Nodes + 1
3. Cyclomatic complexity =number of
regions in the control flow graph
DETERMINE CYCLOMATIC COMPLEXITY
Cyclomatic complexity = edges - nodes + 2p
p = number of unconnected parts of the graph.
Cyclomatic
complexity =
8-7+ 2*1= 3.
DETERMINE CYCLOMATIC COMPLEXITY
Cyclomatic complexity = edges - nodes
+ 2p
Cyclomatic complexity
= 7-8+ 2*2= 3.
DETERMINE CYCLOMATIC COMPLEXITY
Cyclomatic complexity= Number of
Predicate Nodes + 1
Cyclomatic
complexity
= 2+1= 3.
DETERMINE CYCLOMATIC COMPLEXITY
Cyclomatic complexity =number of regions in the
control flow graph
Cyclomatic complexity
=3
FIND A BASIS SET OF PATHS
Path 1: 1, 2, 3, 5, 6, 7.
Path 2: 1, 2, 4, 5, 6, 7.
Path 3: 1, 6, 7.
GENERATE TEST CASES FOR EACH
PATH
We have 3 paths so we need at least one test case to
cover each path.
Write test case for these paths .
CONCLUSIO
N
BASIC PATH TESTING HELPS US TO REDUCE REDUNDANT TESTS.
IT SUGGESTS INDEPENDENT PATHS FROM WHICH WE WRITE TEST CASES NEEDED
TO ENSURE THAT EVERY STATEMENT AND CONDITION CAN BE EXECUTED AT LEAST
ONE TIME.