You are on page 1of 31

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
Basic concepts- nodes, links and paths

NODE: process blocks , decisions and statements.


LINKS: links are directed lines with arrows indicating direction
of flow.
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.
Path selection criteria

Defining complete testing:


Exercise every path from entry to exit.
Exercise every statement or instruction at least once.
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

any testing strategies shall fulfil two basic criteria exercise


every statement at least once and execute every branch in all
possible directions at least once.

path testing
statement testing
branch testing
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)?
Testing of path involves loops

Types of loops:
single loop
nested loops
concatenated loops
Predicates, Path Predicates and Achievable paths

Predicate:
Its a logical function evaluated at decision point.
Predicates, Path Predicates and Achievable paths

Path predicate:
A predicate associated with a path is called a predicate
path.
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: Achievable and
Unachievable Paths

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
Path Sensitization

Path sensitization is the act of finding a set of


solutions to a path predicate expression.
Path Sensitization

Fig: Predicate notational representation


Path Sensitization

Predicate values for the given path


Path Sensitization
Path Sensitization : Example
Path Sensitization : Example
Path instrumentation

You might also like