White-Box Testing

24
White-Box Testing Pfleeger, S. Software Engineering Theory and Practice 2 nd Edition. Prentice Hall, 2001. Ghezzi, C. et al., Fundamentals of Software Engineering. Prentice Hall, 2002. Pressman, R., Software Engineering A Practitioner’s Approach, Mc Graw Hill, 2005. 1209

description

White-Box Testing. Pfleeger, S. Software Engineering Theory and Practice 2 nd Edition. Prentice Hall, 2001. Ghezzi, C. et al., Fundamentals of Software Engineering. Prentice Hall, 2002. Pressman, R., Software Engineering A Practitioner’s Approach, Mc Graw Hill, 2005. 1209. - PowerPoint PPT Presentation

Transcript of White-Box Testing

Page 1: White-Box Testing

White-Box Testing

Pfleeger, S. Software Engineering Theory and Practice 2nd Edition. Prentice Hall, 2001.Ghezzi, C. et al., Fundamentals of Software Engineering. Prentice Hall, 2002.Pressman, R., Software Engineering A Practitioner’s Approach, Mc Graw Hill, 2005.

1209

Page 2: White-Box Testing

White Box Testing• Also known as:

– Glass box testing– Structural testing

• Test set is derived from structure of code • Code structure represented as a Control Flow Graph• Goal is to cover the CFG

Page 3: White-Box Testing

Control Flow Graphs• Programs are made of three kinds of statements:

Page 4: White-Box Testing

Control Flow Graph (CFG)

Sequence If-then-else If-then Iterative

Page 5: White-Box Testing

Example 1: CFG

1. read (result);2. read (x,k)3. while result < 0 then {4. ptr false5. if x > k then6. ptr true7. x x + 18. result result + 1 }9. print result

Page 6: White-Box Testing

Write a CFGExample 2

1. if (a < b) then 2. while (a < n)3. a a + 1;4. else 5. while (b < n)6. b b + 1;

Page 7: White-Box Testing

Answers Example 3

1. read (a,b); 2. if (a 0 && b 0) then {3. c a + b;4. if c > 10 then 5. c max6. else c min }7. else print ‘Done’

Page 8: White-Box Testing

AnswersExample 4

1. read (a,b); 2. if (a 0 || b 0) then {3. c a + b4. while( c < 100)5. c a + b; }6. c a * b

Page 9: White-Box Testing

Cyclomatic Complexity• Software metric for the logical complexity of a program.• Defines the number of independent paths in the basis set of a

program

• Provides the upper bound for the number of tests that must be conducted to ensure that all statements been have executed at least once

• For Edges (E) and Nodes (N) V(G) = E – N + 2

Page 10: White-Box Testing

Complexity of CFGs

1

2

3

1 3,4

5 6

Join

3,4

5

Join

Page 11: White-Box Testing

Example1

2,3

6

10

8

4,5

9

7

11

Page 12: White-Box Testing

Example 1: CFG

3

4,5

6

Join

9

7,8

1,2

Page 13: White-Box Testing

Example 21

2

3

Join

5

6

Page 14: White-Box Testing

Answers1,2

Join

3,4

5 6

Join

7

Page 15: White-Box Testing

Answers

1, 2

3

Join

4

5

6

Page 16: White-Box Testing

Criteria

• Statement coverage• Branch coverage• Condition coverage

• (lots of others …)

Page 17: White-Box Testing

Branch Coverage• Each edge of a program’s CFG is

traversed at least once in some test.

• Independent paths: – 1, 2, 3, 9– 1, 2, 3, 4, 5, 6, 7, 8, 3, …, 9– 1, 2, 3, 4, 5, 7, 8, 3, …, 9

Example 1

3

4,5

6

Join

9

7,8

1,2

Page 18: White-Box Testing

Criteria• Statement coverage• Branch coverage• Condition coverage

– Every complex condition is made true and false by every possible combination

– E.G., (x and y)• x = true, y = true• x=false, y=true• x = true, y= false• x =false, y = false

Page 19: White-Box Testing

AND Condition

1, 2A

2B

Join

3

4

Page 20: White-Box Testing

OR Condition

1,2A

3

Join

4

2B

5

Page 21: White-Box Testing

Path Coverage-1• Every distinct path through code is

executed at least once• Basis set does not yield minimal test set• Example

1. read (x)2. read (z)3. if x 0 then begin4. y x * z;5. x z end6. else print ‘Invalid’ 7. if y > 1 then8. print y9. else print ‘Invalid’

• Test Paths:1, 2, 3, 4, 5, J1, 7, 8, J21, 2, 3, 4, 5, J1, 7, 9, J21, 2, 3, 6, J1, 7, 8, J2,1, 2, 3, 6, J1, 7, 9, J2

1,2,3

4,5

Join1

6

7

8

Join2

9

Page 22: White-Box Testing

Def-Use Coverage• Def-use coverage: every path

from every definition of every variable to every use of that definition is exercised in some test.

• Example1. read (x)2. read (z)3. if x 0 then begin4. y x * z;5. x z end6. else print ‘Invalid’ 7. if y > 1 then8. print y9. else print ‘Invalid’

1,2,3

4,5

Join

6

7

8

Join

9

Def: x, zUse: x

Def: y, xUse: x, z

Use: none

Use: y

Use: y Use: none

Test Path: 1, 2, 3, 4, 5, 7, 8, J

Page 23: White-Box Testing

Strength of Coverage

Page 24: White-Box Testing

What paths don’t tell you

• Timing errors• Unanticipated error conditions• User interface inconsistency (or anything

else)• Configuration errors• Capacity errors