Unit 1 Flow Graph and Path Testing
Unit 1 Flow Graph and Path Testing
testing
Basic concepts of path
testing
Path testing:
Path Testing is a structural testing method
based on the source code or algorithm and NOT
based on the specifications.
Test cases based on Basis path testing grantee to
execute every statement in program at least
once.
THE BUG ASSUMPTION:
The bug assumption for the path testing
strategies is that something has gone wrong
with the software that makes it take a
different path than intended.
As an example "GOTO X" where "GOTO Y" had
been intended.
Flow graph
A flow graph depicts the logical control flow
using the following notations
Flow graph
• Each circle, called flow graph node, represents
one or more procedural statements.
• The arrows called as links or edged represent
flow of control.
• Areas bounded by edges are called regions. while
counting regions the area outside the graph is
also taken as a region.
• Each node containing a condition is called a
predicate node and has 2 or more edges out of it.
Flow graph
Flow Graph Elements:
A flow graph contains four different types of
elements.
Process Block
Decisions
Junctions
Case Statements
Flow graph
Process block:
X
Decision:
Yes Do Function1()
Input
If A = B
No Do Function2()
Junctions:
interrupt
1 2
Case statement:
Case n
Control Flow Graph Vs Flow Charts
Inside details of a process block are not Every part of the process block are
shown drawn
INPUT X, Y
Z := X + Y
V := X - Y
IF Z >= 0 GOTO SAM
JOE: Z := Z + V
SAM: Z := Z - V
FOR N = 0 TO V NO
Z := Z - 1 INPUT X, Y Z := X + Y V := X - Y Z >= 0 ? JOE
NEXT N
END
LOOP SAM Z := Z + V
Z := Z - 1 N := 0 Z := Z - V
NO
N=V? N := N+1
INPUT X, Y
Z := X + Y
V := X - Y
IF Z >= 0 GOTO SAM
JOE: Z := Z + V
SAM: Z := Z - V
FOR N = 0 TO V NO
Z := Z - 1 P1 Z >= 0 ? JOE
NEXT N
END
LOOP SAM P2
P4 P3
NO
N=V? P5
YES END
NO
NO
Fig: Alternative Flow graphs for same logic (Statement "IF (A=0) AND (B=1)
THEN . . .").
Flow graph and flow chart generation
1.Hand-drawn by programmer.
2.Automatically produced by a flowcharting program
based on a mechanical analysis of the source code.
3.Semi automatically produced by a flow charting program
based in part on structural analysis of the source code
PATH TESTING
Basic concepts- nodes, links and paths
NODE: process blocks , decisions and statements.
LINKS: links are directed lines with arrows indicating direction of
flow.
SEGMENTS : it is a link, single process between two nodes.
PATH SEGMENT : Succession of consecutive links that belongs to the
same path
PATH: a path is a sequence of statements that starts from any node
in the program and ends in some other node or same node in the
program.
LENGTH OF A PATH: length of a path is measured by number of links
in that path.
NAME OF A PATH: the name of the path is the name of the node
along the path.
COMPLETE PATH: this denotes a path that starts at entry and goes to
an exit.
Entry/Exit routines, process block and nodes
Single entry/single exit is preferable
– called well-formed routines
– formal basis for path testing
– tools could generate test cases
Multi- Entry/Multi –Exit Routines(ill-formed)
– A weak approach
– Integration issues
– Theoretical and tools based issues
Fundamental Path selection criteria
Defining complete testing:
1. Exercise every path from entry to exit.
2. Exercise every statement or instruction at least once.
3. Exercise every branch and case statement, in each direction at
least once.
achieve C1 + C2 coverage)
Types of loops:
single loops
nested loops
concatenated loops
Horrible loops
1. Single loops: The loops that has only one iteration.
2.Nested Loops: The Nested loops are quite complicated ie., a loop within
another loop is known as Nested loop. It is very expensive to test the path which
contains nested loop because of its complexity.
3. Concatenated Loops: Concatenated loops are the loops which reside the
beside the other on the same path
4.Horrible Loops: Horrible are the complexed of all the three loops and may
involve nested loops, intersecting loops, cross connected loops all in one
structure.
LOOPS:
1 2 3 4
1 2
Concatenated Loops
Single loops
1 2 3 4
Nested Loops
UNIT-1 PATH TESTING
Horrible LOOPS:
Dr.M. PRABHAKAR
Testing in single loop statement
CASE 1: minimum = 0 , maximum = N, No excluded values
1. Check if the loop can be bypassed (N = 0).
– If not, there may be a bug or the minimum is incorrect.
2. Check if the loop variable can be negative or specify a negative iteration
count.
3. Test different iteration cases:
– One iteration (N = 1)
– Two iterations (N = 2)
– Typical number of iterations (Min < N < Max)
– One less than the maximum (N = Max - 1)
– One more than the maximum (N = Max + 1)
4. Detect data flow issues:
– Variables defined but not used within the loop.
– Variables initialized inside the loop but used outside.
CASE 2: minimum = +ve , No excluded values
1. Check what happens if the loop control variable is too low.
– What prevents it from going below the minimum?
2. Test different iteration cases:
– Minimum iterations (N = 1)
– Minimum + 1 iterations (N = 2)
– Typical value of N
– Maximum value of N
– Maximum + 1 iterations
“These tests ensure the loop behaves correctly at boundary
values and within expected ranges.”
Code :
for i in range(1, 6): # Loop runs from 1 to 5
print(f"processing {i}")
print(f“processing {i}")
range(1, 10), Exclude 1 Should print 2-9
Step 1: Keep i fixed at its minimum and vary j across all test values.
Step 2: Keep i at its typical value and vary j.
Step 3: Keep i at its maximum and vary j.
example,
if (x > 10) {path 1: x>10 & y<5 => executes z=x+y
if (y < 5) { path 2 : x>10 & y>=5 => skip
z = x + y; path 3 : x < =10 => skip everything
}
}
Predicates, Path Predicates and Achievable paths
• Predicate interpretation:
The act of symbolic substitution of operations along
the path in order to express the predicate solely in terms of
the input vector is called interpretation.
Predicates, Path Predicates and Achievable paths
possible ways.
• If all the values are tested in all possible directions, then we can say that 100%
1.Assignment Blindness
2. Equality Blindness
3. Self Blindness
1.Assignment Blindness:
A variable is assumed to be correctly assigned, but due to incorrect logic or
placement, it is either not assigned or reassigned unexpectedly.
2. Equality Blindness:
Equality Blindness occurs when a value is generated by a decision, and if
that value passes through multiple checks (predicates), it is considered valid, even
if it's not actually correct. (a=5,b=10, a+b=15)
3. Self Blindness:
Sometimes, both the correct and the wrong predicate becomes similar
to each other depending on the value assigned to the assignment statement.
Correct
Buggy
X := A (check for any X=A)
X := A
IF X - 1 > 0 THEN
IF X + A -2 > 0 THEN
… …
Path Sensitization
_
B l D
1
9 0
D
m
Path Predicate Values
abcdef AC
aghcimkf ABCD
aglmjef A BD
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS
_
B l D
1
9 0
D
m
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS
1 4 6 2
a Y d Y g
_ Correlated paths => some paths are
unachievable
Y Y
c
f
b d f
_ 4 5 If a chosen sensible path is not achievable,
Y -design can be simplified.
3
-get better understanding of correlated decisions
1 6 2
a Y g
Y
c 4 5
’ d’ ’
e
PATH INSTRUMENTATION
PATH INSTRUMENTATION:
For example, the five cases could be totally jumbled and still the
outcome would be the same.
Path Instrumentation is what we have to confirm that the
outcome was achieved by the intended path.
Dr.M. PRABHAKAR
Two Link Marker Method:
the Two Link Marker Method is a technique used to detect cycles
and validate traversal in directed graphs. It places two markers:
First Marker: Indicates a node has been visited.
Second Marker: Confirms the path is complete.
PATH INSTRUMENTATION
Link Counter :
1 0 True 1
2 1 True 2
3 2 True 3
4 3 False(exit) -
APPLICATINS OF PATH TESTING
3. Maintenance:
Software maintenance involves updates, bug fixes, or improvements.
Path testing ensures that any modifications do not negatively impact the
existing execution flows.
Helps maintain software stability by identifying unexpected side effects of
code changes.
4. Rehosting
When a software system is migrated to a new platform or environment, path
testing ensures its correct functionality.
Detects any compatibility issues that may arise due to changes in hardware,
OS, or dependencies.
Prevents failures caused by different execution behaviours in the new
environment.