You are on page 1of 39

PATH TESTING

INPUT

OUTPUT
Observations
– Nodes 4-8 are a sequence, there
is no branching
– Nodes 9-12 are an IF-THEN-
ELSE construct
– Nodes 13-22 are nested IF-
THEN-ELSE constructs
– Nodes 4 and 23 are the program
source and sink nodes
• Single entry, single exit
– There are no loops, so this is a
directed acyclic graph
Decision – To – Decision Paths
(DD-Paths)

The best known form of structural testing is basedon


decision-to-decision path
A DD-paths is a sequence of statements that begins
with the ‘outway’ of a decision statement and ends
with the ‘inway’ of the next decision statement
– There are no internal branches in such a sequence
– Like a row of dominos
DD-Path – formal definition
A decision-to-decision path (DD-Path) is a chain in
a program graph such that:
Case 1: consists of a single node with indeg=0
Case 2: consists of a single node with outdeg=0
Case 3: consists of a single node withindeg ≥ 2 or
outdeg ≥ 2
Case 4: consists of a single node with indeg =1, and
outdeg = 1
Case 5: it is a maximal chain of length ≥ 1
DD-Paths are also known as segments
Program DD-Path Name Case of
Graph Nodes Definition
4 First 1
5-8 A 5
9 B 3
10 C 4
11 D 4
12 E ?
13 F ?
14 G ?
15 I
16 J
17 ?
18 ?
19
20
21
22
23 LAST 2
Program DD-Path Case of
Graph Nodes Name Definition
4 First 1

5-8 A 5

9 B 3

10 C 4

11 D 4

12 E 3

13 F 3

14 H 3

15 I 4

16 J 3

17 K 4

18 L 4

19 M 3

20 N 3

21 G 4

22 O 3

23 LAST 2
Program DD-Path Case of
Graph Nodes Name Definition
4 First 1

5-8 A 5

9 B 3 SOURCE
10 C 4

11 D 4

12 E 3

13 F 3

14 H 3

15 I 4

16 J 3

17 K 4

18 L 4

19 M 3

20 N 3

21 G 4

22 O 3

23 LAST 2 SINK
Structural Test Coverage Metrics
1.Statement and predicate testing:

We allow statement fragments to be individual


nodes
• Hence, levels C0 & C1 collapse into 1 level

Nodes 8,9,10 are a complete IF-THEN-ELSE


statement, if we
follow C0, we could only execute one of the
decision
alternatives and satisfy the statement
coverage criteria
2. DD-Path testing
When the C1 metric is exercised, we traverse every
edge of the DD-Path, and thus every fragment, as
opposed to every node.
Longer DD-Paths generally represent complex
computations
For IF-THEN-ELSE statements, the true and the false
branches are covered (C1p)
• For CASE statements, every clause is covered
3.Dependent Pairs of DD-Paths
The most common dependency among pairs of
DD-Paths is the define/reference relationship
(define/use)
10 .Then isatriangle= true
13.If istriangle
11. Else isatriangle=false
21. Else output(“not a triangle”)
4.Multiple Condition Coverage
Node B corresponds to statement 9 in the program
graph, line 9:
IF ( a < b+c ) AND ( b < a+c ) AND ( c < a+b )
– Node H corresponds to statement 14 in the
program graph:
IF ( a=b ) AND ( b=c )
Rather than simply traversing such predicates to
their
TRUE and FALSE outcomes, we could investigate the
different ways that each outcome can occur
5. Loop coverage
 Types of loops
 1. Concatenated loops: a sequence of disjoint loops
 2. Nested loops: one is contained inside the other
 3. Knotted loops: are Horrible loops!, when it is possible to branch into or out from
the middle of a loop, and these branches are internal to other loops
V(G)=e-n+2p; arbitrary directed graph
V(G)=e-n+p; strong directed graph
e– no of edges, n—no of nodes, p—no of
connected regions
BASIS PATH TESTING EXAMPLE
V(G)=e-n+2p
=10-7+2(1)
=5
V(G)=e-n+p(strongly connected graph)
 11-7+1
=5
Original P1-First- A-B-C-E-F-H-J-K-M-N-O-LAST
Scalene
Flip P1 at B P2- First-A-B-D-E-F-H-J-K-M-N-O-LAST
Infeasible
Flip P1 at F P3- First-A-B-C-E-F-G -O-LAST
Infeasible
Flip P1 at H P4- First-A-B-C-E-F-H-I-N-O-LAST
Equilateral
Flip P1 at JP5- First-A-B-D-E-F-H-J-L-M-N-O-LAST
Isosceles
Data Flow Testing
Data flow testing
– Forms of structural testing that focus on the points at
which variables receive values and the points atwhich
these values are used or referenced
• We will study two forms of data flow testing
– Define/Use Testing
– Program Slicing
 Define/reference anomalies
– A variable that is defined but never referenced
– A variable that is used but never defined
– A variable that is defined twice before it is used.
Define/Use Testing Definitions
Definition:
– Node n ÎG(P) is a defining node of the variable v Î V,
written as DEF(v,n), iff the value of the variable v is
defined at the statement fragment corresponding to
node n.
Node n ÎG(P) is a usage node of the variable v Î V,
written as USE(v,n), iff the value of the variable v is
used at the statement fragment corresponding to
node n.
Define/Use Testing Definitions
A usage node USE(v,n) is a predicate use (denoted
as P-use), iff the statement n is a predicate statement;
otherwise USE(v,n) is a computation use, (denoted
C-use)
Program Graph & DD-Paths
for the Commission Problem
DD-Path from the program graph
DD-Path Graph of the
commission program
du-Paths for Stocks:
DEF(stocks,15) andUSE(stocks,17)
path<15,17>

No other is defining nodes are used for stocks;


therefore, this path also definition clear
du-Paths for Locks:
DEF(locks,13),DEF(locks,19),
USE(locks,14),and USE(locks,16).
These yield four du-paths:

P1=<13,14>
P1=<13,14,15,16>
P1=<19,20,14>
P1=<19,20,14,15,16>
Du-path Test Coverage Metrics Definitions
Slice Based Testing
The second type of data flow testing
 A program slice is a set of program statements that
contribute to, or affect a value for a variable at some
point in the program.
 The idea of slicing is to divide a program into
components that have some useful meaning
S(V,n)
Slice Based Testing
 The USE relationship pertains to five forms of usage:
– P-use: used in a predicate (decision)
– C-use: used in a computation
– O-use: used for output
– L-use: used for location (e.g. pointers)
– I-use: used for iteration (internal counters, loop
indices)
Definition nodes:
– I-def: defined by input
– A-def: defined by assignment
du-Paths for Locks:
DEF(locks,13),DEF(locks,19),
USE(locks,14),and USE(locks,16).
Slice Based Testing
S1: S(locks,13) = {13} (defining node I-def)
• S2: S(locks,14) = {13,14,19,20}
• S3: S(locks,16) = {13,14,16,19,20}
• S4: S(locks,19) = {19} (defining node I-def)

You might also like