1
STRUCTURAL TESTING
2
3
4
5
5
8 9
8 9
8/(9-1)=1
6
7
8
9
Test Coverage Metrics
• Test coverage metrics are a device to measure the extent
to which a set of test cases covers a program.
• Most quality organizations now expect the C1 metric
(DD-Path coverage) as the minimum acceptable level of
test coverage.
• The statement coverage metric (C0) is still widely
accepted: it is mandated by ANSI Standard 187B and has
been used successfully throughout IBM since the mid-
1970s.
10
Test Coverage Metrics
Metric Description of Coverage
C0 Every Statement
C1 Every DD-Path
C1P Every predicate to each outcome
C2 C1 Coverage + loop coverage
11
Cd C1 Coverage + every dependent pair of DD-Paths
CMCC Multiple condition coverage
Cik Every program path that contains up to k repetitions of a
loop (usually k=2)
Cstat “Statistically significant” fraction of paths
C∞ All possible execution paths
12
Metric Based Testing –
Statement and Predicate Coverage Testing
• Statement coverage based testing aims to create test
cases that collectively exercise all statements in a
program.
• Predicate coverage (or branch coverage, or decision
coverage) based testing aims to create test cases that
evaluate each simple predicate(VARIABLES) of the
program.
• These test coverage metrics require that we find a set of
test cases such that when executed ,every node of the
graph is traversed at least once.
13
DD-Path Testing
DD-Path Graph Edge Coverage C1
1 2
Here a T,T and F,F
combination will suffice
T P1 F
to have DD-Path Graph
edge coverage or
Predicate coverage C1
T P2 F
14
DD-Path Coverage Testing C1P
• This is the same as
the C1 but now we
must consider test P1
cases that exercise all T F
possible outcomes
of the choices for if-
else statement T,T, T P2 F
T,F, F,T, F,F for the
predicates P1, and P2
respectively, in the
DD-Path graph. For
CASE statements
each clause is covered.
15
Dependent DD-Path Pairs Coverage
Testing (Cd = C1+Dependent pairs )
• In simple C1 coverage criterion we are interested simply
to traverse all edges in the DD-Path graph.
• If we enhance this coverage criterion by ensuring that
we also traverse dependent pairs of DD-Paths also we
may have the chance of revealing more errors that are
based on data flow dependencies.
• More specifically, two DD-Paths are said to be dependent
if there is a define/reference relationship between these
DD-Paths, in which a variable is defined (receives a value) in
one DD-Path and is referenced in the other.
• In Cd testing we are interested on covering all edges of
the DD-Path graph and all dependent DD-Path pairs.
16
C & H are such pairs, as are
DD paths D & H.
IsATriangle is set to true at
node C and false at node D.
Node H is a branch taken when
ISATriangle is true at node B,
so any path containing nodes D
and H is infeasible.
17
18
19
20
21
22
2
23
24
Multiple Condition Coverage Testing(CMCC)
• Look closely at the compound conditions in DD-Paths B and H.
• Instead of simply traversing such predicates to their true and false
outcomes, we should investigate the different ways that each outcome
can occur.
• One possibility is to make a truth table; a compound condition of
three simple conditions would have eight rows, yielding eight test
cases.
• Another possibility is to reprogram compound —predicates.-into -
nested.
• simple if-then-else -logic, -which will result an more DD-Paths to
cover. 25
• Example: “if (A or B)” requires 4 test cases:
A = True, B = True
A = True, B = False
A = False, B = True
A = False, B = False
• The problem: For n conditions, 2n test cases are needed,
and this grows exponentially with n.
26
Loop Coverage Testing
First
First First
A A
A
B
B B
C
C C
D
D D
Last
Last
Last
Concatenated, Nested and Knotted loops
27
•Concatenated loops are simply a sequence of disjoint loops.
•while nested loops are such that one is contained inside another.
•Knotted loops cannot occur when the structured programming
precepts are followed.
•When it is possible to branch into (or out from) the middle of a
loop, and these branches are internal to other loops, the result is
Beizer's knotted loop. (Other sources define this as a knot —how
appropriate.)
28