Вы находитесь на странице: 1из 6

Motivation

Flowgraphs and Path Testing


• Mainly target at structural faults in our fault
model.
• Path testing is basis from which more
sophisticated methods are “grown”
Ye Wu • Path testing is traditional for unit testing
http://www.ise.gmu.edu/~wuye

9/19/2001 © Ye Wu 1 9/19/2001 © Ye Wu 2

Path testing terminologies Path testing terminologies


• Control Flow Graph (CFG) • Nodes – represent Basic Blocks (Begin
A graphical representation of a program’s control node, end node)
structure. • Arcs – represent control moving from one
• Basic block (process block) – Maximal sequence node to another node
of statements such that if one statement is
executed, all statements in the basic block are • Decision – branch, node with 2 or more
reached. outgoing arcs
– No branch • Junction – Node with 2 ore more incoming
– Single entry, single exit edges
9/19/2001 © Ye Wu 3 9/19/2001 © Ye Wu 4

System.out.print("Please input an integer:"); How to Derive CFG – if


InputStreamReader isr =
new InputStreamReader (System.in); S1
BufferedReader br =
new BufferedReader (isr);
t = Integer.parseInt(br.readLine()); S1
flag = false;
if (t > 0) { if (e) if
for( i = 2; i <= ( int)Math.sqrt((double)t); i++) {
S2 e
if ( t % i == 0) { -e
System.out. println("It's COMPOSITE number!");
flag = true;
endif S2
break; } S3
}
if (!flag) System.out.println("It's PRIME number"); S3
}
else System.out.println("Please input a positive NUM!");
9/19/2001 © Ye Wu 5 9/19/2001 © Ye Wu 6

1
How to Derive CFG – if-else How to Derive CFG – while
S1 S1
S1
If (e) S1
if-else while
S2 e -e while (e) e
Else S2 -e
S3 S2 S3 end while S2

endif S3
S4 S4 S3

9/19/2001 © Ye Wu 7 9/19/2001 © Ye Wu 8

How to Derive CFG – for How to Derive CFG – repeat


S1

S1
for
S1 i≤B S1
for i = A to B do repeat S2
S2
S2
S2 -e
i>B
end for until (e) repeat
i= i+1
S3 S3 e
S3
S3
9/19/2001 © Ye Wu 9 9/19/2001 © Ye Wu 10

How to Derive CFG – case How to Derive CFG – case


S1 S1 S1
switch (X)
switch (X)
case A -A case A:
case A: switch
A S2 ___
S2
case B: A A|B|…
case B: B
S3
S2
B
case B -B S3
otherwise S4
otherwise S2 S3
S3 S4 S4
S4
end case
end case
S5
S5 S5
S5
9/19/2001 © Ye Wu 11 9/19/2001 © Ye Wu 12

2
System.out.print("Please input an integer:");
InputStreamReader isr = Sa
new InputStreamReader (System.in); S1
S1 BufferedReader br = S1;
new BufferedReader (isr); if (t > 0) {
t = Integer.parseInt(br.readLine()); for( i = 2; p; i++) {
flag = false; if ( t % i == 0) if-else
if (t > 0) { S2 t>0 t >=0
for( i = 2; i <= ( int)Math.sqrt((double)t); i++) { }
if ( t % i == 0) { if (!flag) Sa S4
System.out. println("It's COMPOSITE number!"); S3
S2 flag = true; else
break; } S4 Send
} S3 S4
if (!flag) System.out.println("It's PRIME number");
}
else System.out.println("Please input a positive NUM!");
9/19/2001 © Ye Wu 13 9/19/2001 © Ye Wu 14

t>0 S1 t>0 S1
S1; S1;
if (t > 0) { Sb if (t > 0) {
for for( i = 2; p; i++) { for
for( i = 2; p; i++) { p p
if ( t % i == 0) if ( t % i == 0)
Sb t >=0 if t >=0
S2 !p S2 !p
} }
S2 X
if (!flag) i++; i++;
S3 if (!flag)
else if S3 if
!flag !flag
S4 else
flag flag
S3 S4 S4 S3 S4

Send Send

9/19/2001 © Ye Wu 15 9/19/2001 © Ye Wu 16

Basic Path Coverage Techniques (1) Example


• Statement Coverage if ( a > 0 && b > 0 && c < 0) { … }
– Every statement in the program must be tested
– Each node in CFG has to be covered
condition

• Branch Coverage a > 0 && b > 0 && c < 0


– Each branch must be taken at least once
– Each edge in CFG must be covered decision

9/19/2001 © Ye Wu 17 9/19/2001 © Ye Wu 18

3
Basic Path Coverage Techniques (2) Example
Test case 1: a=1 b=1 c= 1 BC
• Conditional coverage Test case 2: a=1 b=1 c = -1
– Every condition in every decision has evaluated to both
Test case 3: a=1 b =-1 c= 1
True and False for at least once
Test case 4: a=1 b =-1 c = -1
CC MC/DC
Test case 5: a =-1 b=1 c= 1
• Multiple condition/Decision coverage(MC/DC)
Test case 6: a =-1 b=1 c = -1
– Every decision and every condition within the decision
have taken every outcome at least once
Test case 7: a =-1 b =-1 c= 1
Test case 8: a =-1 b =-1 c = -1

9/19/2001 © Ye Wu 19 9/19/2001 © Ye Wu 20

Basic Path Coverage Techniques (3) Terminologies


• Multiple condition coverage • Path Segment (subpath ) – A sequence of arcs
All true-false combinations of conditions for a through the CFG, not necessarily complete.
decision need to be test at least once • Complete path(Path) – A subpath starts from the
– 2n begin node and stop at the end node.
– Infeasible combinations • Length of a subpath – Number of arcs in a
subpath.
• Loop – Subpath that begins and ends at the same
node.

9/19/2001 © Ye Wu 21 9/19/2001 © Ye Wu 22

Basic Path Coverage Techniques (4) Relationships Among Coverage Criteria

• Path coverage • Subsumes


– Every complete path is executed for at least once A testing criteria C1 subsumes C2 is for any test set T that
• Simple path coverage satisfies C1, T also satisfies C2.
– Every simple path (no repeat occurrence of edges) is MC Path
executed for at least once
• Elementary path coverage MC/DC SPath EPath

– Every elementary path (no repeat occurrence of nodes) is CC BC


executed for at least once
SC

9/19/2001 © Ye Wu 23 9/19/2001 © Ye Wu 24

4
Special Considerations Effectiveness of Path Testing
• Handling loops in path testing • Can caught about 60% bugs in unit testing
– Run the loop 0, 1, N times, N is the maximum
– Run the loop, 0, 1, N, a, N-1 • Path testing can not reveal wrong or missing
functions
• Path testing may not catch interface errors
• Boundary Testing
• Path testing can not catch data flow errors
• Path testing can not catch specification errors
• Validate path coverage is difficult
9/19/2001 © Ye Wu 25 9/19/2001 © Ye Wu 26

Test Case Generation Path Sensitizing


• Path selection
– Simple path vs. complicate path Finding a set of input values that will cause
– Incremental vs. big -bang a component to follow a selected path.
– Non functional meaning path
– Loops
– Multi-entry and multi-exit program
– Uncoverable code

9/19/2001 © Ye Wu 27 9/19/2001 © Ye Wu 28

Predicate Expression Predicate Expression


• Predicate interpretation
The act of symbolic substitution of operations along the path • A predicate is said to be process dependent– if a
In order to express the predicate solely in terms of the input v ector. predicate whose truth value can change as a result
input x1 ,x2 ; input x1 ,x2 ; input x1 ,x2 ; of the processing.
if (x1 + x2 > 0) { y = x2 + 7; if (x1 > 0) { y = x2 + 7; }
…… if (x1 + y > 0) { else { y = x1 + 5; }
} …… if (y > 0){ … …}
}
• A pair of predicates whose outcomes depend on
x1 and x 2 are solely (y > 0) ⇔ one or more variables are said to be correlated
depends on inputs. (x1 + y > 0) ⇔ ((x 1 > 0)&&(x2 +7>0))||
_____ predicates.
(x1 + x 2 + 7 > 0) (x1 > 0)&&(x1+5>0))
Path predicate are the specific form of the predicates of the decisions
Along the selected path after interpretation.
9/19/2001 © Ye Wu 29 9/19/2001 © Ye Wu 30

5
Predicate Expression Path Instrumentation
• Path Predicate expression – the set of path Instrument – to modify a program so that it
predicates associated with a path measures coverage while executing.

– Independent, uncorrelated predicates • Link Markers


– Independent, correlated predicates
• Link Counters
– Dependent predicates
• Other instrumentation approaches

9/19/2001 © Ye Wu 31 9/19/2001 © Ye Wu 32

Вам также может понравиться