Structural Testing
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 1
Structural Testing (c) 2007 Mauro Pezz & Michal Young Ch 12, - - PowerPoint PPT Presentation
Structural Testing (c) 2007 Mauro Pezz & Michal Young Ch 12, slide 1 Learning objectives Learning objectives Understand rationale for structural testing Understand rationale for structural testing How structural (code-based
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 1
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 2
– “S
tructural” testing is still testing product functionality against its specification. Only the measure of thoroughness has changed.
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 3
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 4
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 5
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 6
the implementation
inadequate functional test suites
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 7
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 8
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 9
{char *eptr = encoded ; int cgi _decode (char *encoded , char *decoded ) A { p ; char *dptr = decoded ; int ok = 0; while (*eptr) { B
T0 = {“”, “test”,
char c; c = *eptr; if (c == '+') {
True False T False
C
{ , test ,
“test+case%
1Dadequacy”} 17/ 18 = 94% S tmt Cov.
*dptr = ' '; }
True True False False
elseif (c == '%') { D E
T1 = {“adequate+test% 0Dexecuti
7U”}
int digit _high = Hex_Values [*(++eptr)]; int digit _low = Hex_Values [*(++eptr)]; if (digit_high == -1 || digit_low == -1) {
True False
else *dptr = *eptr; } F G
18/ 18 = 100% S tmt Cov. T2 = {“% 3 ” “% A” “ b”
} else { *dptr = 16 * digit_high + digit_low; } H I
{“% 3D”, “% A”, “a+b”,
“test”}
18/ 18 = 100% S tmt Cov.
*dptr = '\0'; return ok ; } ++dptr; ++eptr; } L M
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 10
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 11
{char *eptr = encoded ; char *dptr = decoded ; int cgi _decode (char *encoded , char *decoded ) A
coverage may not imply
int ok = 0; h while (*eptr ) { True False B
executing all branches in a program
char c; c = *eptr; if (c == '+') { *dptr = ' '; } True False elseif (c == '%') { C D E
– S uppose block F were missing – S tatement adequacy
} int digit_high = Hex_Values [*(++eptr)]; int digit_low = Hex_Values [*(++eptr)]; if (digit_high == -1 || digit_low == -1) { True False else { *dptr = *eptr; } F G
would not require false branch from D to L
T3 = {“” “ % 0D % 4J”}
} True else { *dptr = 16 * digit_high + digit_low; } False H I
{“”, “+% 0D+% 4J”} 100% S tmt Cov.
No false branch from D
*dptr = '\0'; return ok ; } } ++dptr; ++eptr; } L M
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 12
} }
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 13
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 14
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 15
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 16
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 17
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 18
true false
true false
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 19
(((a || b) && c) || d) && e ((( || ) ) || )
Test a b c d e Case (1) T T T (1) T — T — T (2) F T T — T (3) T — F T T (4) F T F T T (5) F F — T T (5) F F — T T (6) T — T — F (7) F T T — F (8) T — F T F (9) F T F T F (9) F T F T F (10) F F — T F (11) T — F F — (12) F T F F — (13) F F — F — (13) F F F
number, but not always
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 20
number, but not always
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 21
Test a b c d e
Case (1) true
true (2) false true true
true (3) true
true true true (6) true
false (11) true
false
(11) true false false false (13) false false
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 22
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 23
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 24
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 25
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 26
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 27
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 28
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 29
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 30
1 = statement coverage
2 = branch coverage
n+2 = coverage of n consecutive LCS
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 31
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 32
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 33
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 34
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 35
– defensive programming – code reuse (reusing code that is more general than strictly required for the application)
– interdependent conditions interdependent conditions
– interdependent decisions
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 36
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 37
(c) 2007 Mauro Pezzè & Michal Young Ch 12, slide 38