0% found this document useful (0 votes)
8 views

Unit 1 Flow Graph and Path Testing

The document discusses path testing, a structural testing method that ensures every statement in a program is executed at least once. It explains flow graphs, their components, and the importance of path selection criteria for effective testing, including coverage of all paths, statements, and branches. Additionally, it outlines various types of loops and strategies for testing them, emphasizing the complexity of nested and concatenated loops.

Uploaded by

ARCHANA MANNE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

Unit 1 Flow Graph and Path Testing

The document discusses path testing, a structural testing method that ensures every statement in a program is executed at least once. It explains flow graphs, their components, and the importance of path selection criteria for effective testing, including coverage of all paths, statements, and branches. Additionally, it outlines various types of loops and strategies for testing them, emphasizing the complexity of nested and concatenated loops.

Uploaded by

ARCHANA MANNE
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 63

Flow graph and path

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:

Input Do Process Expected Output

X
Decision:

Yes Do Function1()

Input
If A = B
No Do Function2()
Junctions:
interrupt

1 2
Case statement:

Case Value Input


Case 1

Case 2 One Output


Case 3

Case n
Control Flow Graph Vs Flow Charts

Control Flow Graph Flow Chart


Focuses on Inputs, Outputs, and the Focuses on the process steps inside
control flow into and out of the block.

Inside details of a process block are not Every part of the process block are
shown drawn

ref boris beizer 11


Notational evolution - Creation of Control Flow chart from a program

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

YES END One to One Flow Chart


Notational evolution - Creation of Control Flow Graph from a program

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

Simplified Flow Graph


Flow graph-program correspondence
• Flow graph is a pictorial representation of a program and not the
program itself
• The translation from a flow graph element to a statement and
vice versa is not always unique.

IF A=0 & B=1


YES IF B=1 YES IF A=0 YES
?
NO

NO
NO

Fig: Alternative Flow graphs for same logic (Statement "IF (A=0) AND (B=1)
THEN . . .").
Flow graph and flow chart generation

• Control flow graphs are simplified version of the flow chart.

flow charts can be:

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.

If prescription 1 is followed then 2 and 3 are automatically followed.


Path testing criteria
Path Testing: Execute all possible control flow paths through the
program but typically restricted to entry/exit paths
– implies 100% path coverage
– impossible to achieve
Statement Testing : Execute all possible statements at least once
under some test
– 100% statement coverage Implies 100% node coverage.
– It is denoted by C1
Branch Testing : Execute enough tests assure that every branch
alternative has been exercised at least once under some test
– Implies 100% branch coverage
– Denoted by C2
Path selection example
Practical Suggestions in Path Testing
1. Draw the control flow graph on a single sheet of paper.
2. Make several copies - as many as you will need for coverage (C1+C2)
and several more.
3. Use a yellow highlighting marker to trace paths. Copy the paths onto a
master sheets.
4. Continue tracing paths until all lines on the master sheet are covered,
indicating that you appear to have achieved C1+C2.
5. As you trace the paths, create a table that shows the paths, the
coverage status of each process, and each decision.
Picking appropriate tests paths

• Observe the control flow graph that drawn to represent the


program structure.
• List all these paths that are being identified so that C1+C2
criteria has been fulfilled.
• Form the table from graphical representation with labelled
links.

1.Does every decision have Y & N (C2)?


2.Has every alternative path of each case statement has covered (C2)?
3.Is every three way branch covered (C2)?
4.Is every link covered at least once (C1)?
Revised Path Selection Rules

1. Pick the simplest, functionally sensible entry/exit path.

2. Pick additional paths as small variation from previous paths.

(Pick paths with no loops, shorter paths, simple and meaningful)

3. Pick additional paths that have no obvious functional(only to

achieve C1 + C2 coverage)

4. Be comfortable with chosen paths, Play hunches and use

intuition to achieve C1+C2.

5. Don't follow rules slavishly (blindly) - except for coverage


Testing of path involves loops

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}")

Input (Loop Range) Expected behavior

range(1, 2) (1 iteration) Runs once, prints Processing 1

range(1, 6) (Full range) Runs 5 times (1 to 5)

range(1, 1) (Zero iteration) Should not execute

range(1, 4) (Typical case) Runs 3 times (1 to 3)

range(1, 7) (Off-by-One) Should run 6 times, verify


correctness
range(1, 1000000) (Performance) Check for slowdowns/crashes
CASE 3: single loop with excluded
values
Example :
for i in range(1, 10): # Loop from 1 to 9

if i == 5 or i == 7: Input (Loop Range) Expected behavior


range(1, 10), Exclude 5 & Should print all values
# Exclude values 5 and 7 7 except 5 and 7

continue range(1, 3), No exclusions Should print 1, 2

print(f“processing {i}")
range(1, 10), Exclude 1 Should print 2-9

range(1, 10), Exclude Should print only odd


even numbers number

range(-5, 5), Exclude Should print 0, 1, 2, 3, 4


negatives
Nested Loops
To reduce the number of test cases in nested loops, follow this approach:
1. Start with the innermost loop, keeping all outer loops at their
minimum values.
2. Test the innermost loop at these points: minimum, minimum+1,
typical, maximum-1, and maximum. Include out-of-range and
excluded values if needed.
3. Move to the next outer loop, setting inner loops to typical values.
Repeat step 2 for this loop.
4. Continue this process outward until all loops are tested.
5. Test all cases for all loops together.
Figure : Nested Loop Example
Example : for i in range(1, 4): # Outer loop
for j in range(1, 4): # Inner loop
print(f"Processing ({i}, {j})")
1 : Minimum, Maximum, and Typical Values
We test the following values for each loop:
• Minimum: The smallest value (e.g., 1)
• Minimum + 1: Just above the smallest value (e.g., 2)
• Typical: A common middle value (e.g., 2)
• Maximum - 1: Just below the largest value (e.g., 2)
• Maximum: The largest value (e.g., 3)
2. Vary One Loop at a Time

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.

Step 4: Repeat the same by fixing j and varying i.


3. Skipping Unnecessary Combinations
Instead of testing all 9 combinations, we test a subset covering critical
cases:
• (1,1), (1,3), (3,1), and (3,3) for boundary testing.
• (2,2) for a typical case.
• Any out-of-range values if applicable.
Concatenated Loops:
– Concatenated loops fall between single and nested loops in
terms of test cases.
– Two loops are concatenated if you can enter one loop after
exiting the other while moving from start to end.
– If the loops are not on the same path, they are separate and
can be tested individually.
Horrible Loops
• A horrible loop is a combination of nested loops, the
use of code that jumps into and out of loops,
intersecting loops, hidden loops, and cross
connected loops.
– Makes iteration value selection for test cases an awesome
and ugly task, which is another reason such structures
should be avoided
Predicates, Path Predicates and Achievable paths

• Path : A sequence of process links(&nodes)


• Predicate: It’s a logical function evaluated at decision point.
• Compound predicate : two or more predicates combined with AND,OR
etc

• Path predicate: A predicate associated with a path is called a


predicate path.

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

For (x =2 , y = 3) as inputs, we have following predicates:


“x > 0” is “TRUE”
“y > 2” is “TRUE”

Path predicates are:


Path predicate associated with “write ("ONE"); “ is “x > 0”
Path predicate associated with “write ("THREE"); “ is “y > 2”

For (x =2 , y = 3) as inputs, following are the predicate interpretations:


“ if 2 > 0 then ...” is predicate interpretation corresponding to “if x > 0
then ..” for x = 2.
“ if 3 > 2 then ...” is predicate interpretation corresponding to “if y > 2
then ..” for y = 3.
Path Predicate Expressions

• Path Predicate Expressions:


A path predicate expression is a set of Boolean expressions, all
of which must be satisfied to achieve the selected path.
Example:

“if x > 0 then..” and “if y > 2 then..”.


In these branch statements, Predicate Expressions are:
“ x>0” and “y>2”
PREDICATE COVERAGE:
• It is the process of testing all the truth values related to a specific path in all the

possible ways.

• If all the values are tested in all possible directions, then we can say that 100%

predicate coverage is achieved which needs lots of efforts.


TESTING BLINDNESS
Testing blindness occurs when a test follows the right path but reaches it the

wrong way due to a hidden mistake in the test.

They are three types of predicate blindness. They are as follows:

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

Path sensitization is the act of finding a set of solutions to a path predicate


expression.
Heuristic Procedures For Sensitizing Paths:
 Choose easy-to-test paths first and include harder ones only if needed for full
coverage.
 Identify all variables that affect the decision.
 Classify the predicates as dependent or independent.
 Start the path selection with uncorrelated, independent predicates.
 If coverage has not been achieved using independent uncorrelated predicates, extend
the path set using correlated predicates.
 If coverage has not been achieved extend the cases to those that involve dependent
predicates.
 Last, use correlated, dependent predicates.
Path Sensitization

Fig: Predicate notational representation


Path Sensitization : Example
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS

Example of Path Sensitization :


Simple, Independent, Uncorrelated Predicates
No of predicates are :4
3 _
A 5 C
1 4 6 7 2
a A b c C e
d f
_
A g
h
j k
B
8
i
_
B D

_
B l D
1
9 0
D
m
Path Predicate Values
abcdef AC
aghcimkf ABCD
aglmjef A BD
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS

Example of Path Sensitization :


Simple, Independent, Uncorrelated Predicates
4 predicates => 16 combinations
Set of possible paths = 8
3
A 5
1 4 6 7 2
a A b c C e
f
_
A g
h
j k
B
8
i
_
B D

_
B l D
1
9 0
D
m
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS

Path Predicate Value


abcdef AC
abcimjef ACD
abcimkf ACD
aghcdef ABC
aglmkf ABD
PREDICATES, PATH PREDICATES AND ACHEIVABLE PATHS
Example of Path
_ Sensitization : Correlated Independent Predicates
b e
Y Y
3 5

1 4 6 2
a Y d Y g
_ Correlated paths => some paths are
unachievable
Y Y
c
f

Eliminate the correlated decisions.


Reproduce common code.

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 is to confirm that the outcome was achieved by


the expected path.
 It is another from of interpretive trace program, which will run each
and every statements covered so far..
Co-incidental Correctness: The coincidental correctness stands for
achieving the desired outcome for wrong reason.
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.

 The types of instrumentation methods include


 Interpretive Trace Program
 Traversal Marker or Link Marker
 Two Link Marker Method
 Link Counter
PATH INSTRUMENTATION

Interpretive Trace Program:


 An Interpretive Trace Program is a debugging tool that records the execution of a
program, including control flow and variable changes. This helps testers and
developers analyze the program's behavior.
def sum_numbers(n):
trace_log = [] # Store the execution trace
total = 0
for i in range(1, n + 1):
total += i
trace_log.append(f"Iteration {i}: total = {total}") # Log the computation step
return total, trace_log
# Run the function and capture the trace
result, trace = sum_numbers(5)
# Print the trace log
print("Execution Trace:")
print("\n".join(trace))
print(f"Final Result: {result}")
PATH INSTRUMENTATION

Traversal Marker or Link Marker:


 A Traversal Marker (or Link Marker) is a technique used in graph-based program
analysis where markers are placed on nodes or links to track visited paths.
 A simple and effective form of instrumentation is called a traversal marker or link
marker.
 Link marker is also known as Traversal marker which uses small case letters for naming
every link.
 This is used in flow graph testing and path coverage analysis.
PATH INSTRUMENTATION

 Traversal Marker or Link Marker:

Simple path : ijn

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 :

A Link Counter counts how many times a node or link is traversed.


It helps in path coverage analysis and loop iteration testing.
Example:
Consider the loop:
i=0
while i < 3: # Loop executes 3 times
print(f"Iteration {i}")
i += 1
step i value Condition(i<3) Link Count

1 0 True 1

2 1 True 2

3 2 True 3

4 3 False(exit) -
APPLICATINS OF PATH TESTING

APPLICATIONS OF PATH TESTING :


 Path testing is a process which involves all the available paths in a program
from an entry to an exit in such a way that the entire path is thoroughly
tested.
 Path testing implementation and applications can be categorized as
follows:
1. Integration, Coverage and paths in called components
2. New code.
3. Maintenance
4. Rehosting
APPLICATINS OF PATH TESTING

1. Integration, Coverage, and Paths in Called Components:


 Path testing is crucial in software integration, ensuring that different modules
or components interact correctly.
 It verifies that all execution paths in the system, including those in called
functions or submodules, are tested.
 Ensures full coverage of all possible execution flows, reducing the chances of
missed bugs in complex integrations.
2. New Code:
 When developers write new code, path testing ensures that all possible
execution paths are explored and validated.
 It helps catch logical errors, infinite loops, or dead code before the software is
released.
 Ensures the newly added features work as intended and do not break existing
functionality.
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.

You might also like