• No results found

• White-Box Testing

N/A
N/A
Protected

Academic year: 2022

Share "• White-Box Testing"

Copied!
14
0
0

Loading.... (view fulltext now)

Full text

(1)

Lecture 14: Control Flow Graphs

Kenneth M. Anderson

Foundations of Software Engineering CSCI 5828 - Spring Semester, 1999

March 2, 2000 © Kenneth M. Anderson, 2000 2

Today’s Lecture

• White-Box Testing

– Control Flow Graphs

• Coverage Criteria

Testing Approaches

• Black Box Testing

– Tests are selected based on specification of intended functionality

– Tester can only see interface to test subject – Emphasis on proper use of test subject

• White Box Testing

– Tests are selected based on internal structure – Tester can see inside test subject

– Emphasis on proper structure of test subject

White-box Testing: Coverage

• Statement Coverage

• Edge Coverage (Branch Coverage)

• Condition Coverage (Edge Coverage)

• Path Coverage

Details to follow...

(2)

March 2, 2000 © Kenneth M. Anderson, 2000 5

Flow Graphs

• Control Flow

The partial order of statement execution, as defined by the semantics of the language

• Data Flow

The flow of values from definitions of a variable to its uses

Graph representation of control flow and data flow relationships

March 2, 2000 © Kenneth M. Anderson, 2000 6

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

function P return INTEGER is begin

X, Y: INTEGER;

READ(X); READ(Y);

while (X > 10) loop X := X – 10;

exit when X = 10;

end loop;

if (Y < 20 and then X mod 2 = 0) then Y := Y + 20;

else

Y := Y – 20;

end if;

return 2 ∗ X + Y;

end P;

A Sample Ada Program to Test

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

P’s Control Flow Graph (CFG) White-box Testing Criteria

• Statement Coverage

Select a test set T such that, by executing P for each d in T, each elementary statement of P is executed at least once

(3)

March 2, 2000 © Kenneth M. Anderson, 2000 9

All-Statements Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-statements-adequate test set:

March 2, 2000 © Kenneth M. Anderson, 2000 10

All-Statements Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-statements-adequate test set:

(X = 20, Y = 10)

All-Statements Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-statements-adequate test set:

(X = 20, Y = 10) (X = 20, Y = 30)

White-box Testing Criteria

• Edge Coverage

Select a test set T such that, by executing P for each d in T, each edge of P’s control flow graph is traversed at least once

(4)

March 2, 2000 © Kenneth M. Anderson, 2000 13

All-Edges Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-edges-adequate test set:

March 2, 2000 © Kenneth M. Anderson, 2000 14

All-Edges Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-edges-adequate test set:

(X = 20, Y = 10)

All-Edges Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-edges-adequate test set:

(X = 20, Y = 10) (X =15, Y = 30)

White-box Testing Criteria

• Condition Coverage

Select a test set T such that, by executing P for each d in T, each edge of P’s control flow graph is traversed at least once and all possible values of the constituents of compound conditions are exercised at least once

(5)

March 2, 2000 © Kenneth M. Anderson, 2000 17

All-Conditions Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-conditions-adequate test set:

March 2, 2000 © Kenneth M. Anderson, 2000 18

All-Conditions Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-conditions-adequate test set:

(X = 20, Y = 10)

All-Conditions Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-conditions-adequate test set:

(X = 20, Y = 10) (X = 5, Y = 30)

All-Conditions Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-conditions-adequate test set:

(X = 20, Y = 10) (X = 5, Y = 30) (X = 21, Y = 10)

(6)

March 2, 2000 © Kenneth M. Anderson, 2000 21

White-box Testing Criteria

• Path Coverage

Select a test set T such that, by executing P for each d in T, all paths leading from the initial to the final node of P’s control flow graph are traversed at least once

March 2, 2000 © Kenneth M. Anderson, 2000 22

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

(7)

March 2, 2000 © Kenneth M. Anderson, 2000 25

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 26

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

(8)

March 2, 2000 © Kenneth M. Anderson, 2000 29

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 30

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

(9)

March 2, 2000 © Kenneth M. Anderson, 2000 33

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 34

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

(10)

March 2, 2000 © Kenneth M. Anderson, 2000 37

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 38

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

(11)

March 2, 2000 © Kenneth M. Anderson, 2000 41

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 42

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

(12)

March 2, 2000 © Kenneth M. Anderson, 2000 45

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 46

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

(13)

March 2, 2000 © Kenneth M. Anderson, 2000 49

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 50

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

(14)

March 2, 2000 © Kenneth M. Anderson, 2000 53

All-Paths Coverage of P

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

March 2, 2000 © Kenneth M. Anderson, 2000 54

All-Paths Coverage of P

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10)

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

All-Paths Coverage of P

Example all-paths-adequate test set:

(X = 5, Y = 10) (X = 15, Y = 10) (X = 25, Y = 10) (X = 35, Y = 10)

2,3,4 5

6

9

10

12

14

T T

F

F 9 T

F 7 F T

References

Related documents

(Slow) algorithm: Try all paths from each use of a variable, tracing backward in the control flow graph until a def node or previously visited node is

We assessed participants’ drinking and drinking related problems 4 weeks post intervention (both intervention groups) and 4 weeks post assessment (control group) in order to

Leveraging Boeing’s current international operations and supporting development of new

Review only the science that you need to know and eliminate the “fluff”. -I’ve cut away all the “fluff”, so everything I give you is the bare minimum that you need to know

“Provider” shall refer to public or private institutions including universities, health science colleges, professional associations and other training institutions

Este artículo analiza el proceso de militarización de la política contraterrorista de Estados Unidos, mostrando como esta militarización, así como la doctrina preventiva de

Findings show that within the activities classified as intrinsically motivating we can find four major categories: (i) games, songs, videos and films; (ii) magazines,

Subcategories of the IAM market include Web single sign-on (WSSO) and federated single sign-on (FSSO); host/enterprise SSO; user provisioning, including granular authorization