104
White-Box Testing Techniques I Prepared by Stephen M. Thebaut, Ph.D. University of Florida Software Testing and Verification Lecture 7

White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

  • Upload
    others

  • View
    2

  • Download
    0

Embed Size (px)

Citation preview

Page 1: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

White-Box Testing Techniques I

Prepared by

Stephen M. Thebaut, Ph.D.

University of Florida

Software Testing and Verification

Lecture 7

Page 2: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Definition of White-Box Testing

• Testing based on analysis of internal logic(design, code, etc.). (But expected results still come from requirements.)

• Also know as structural testing.

• White-box testing concerns techniques for designing tests; it is not a “level” of testing.

• White-box testing techniques apply primarily to lower levels of testing (e.g., unit and component).

Page 3: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Definition of White-Box Testing

• Testing based on analysis of internal logic(design, code, etc.). (But expected results still come from requirements.)

• Also know as structural testing.

• White-box testing concerns techniques for designing tests; it is not a “level” of testing.

• White-box testing techniques apply primarily to lower levels of testing (e.g., unit and component).

Page 4: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Definition of White-Box Testing

• Testing based on analysis of internal logic(design, code, etc.). (But expected results still come from requirements.)

• Also know as structural testing.

• White-box testing concerns techniques for designing tests; it is not a “level” of testing.

• White-box testing techniques apply primarily to lower levels of testing (e.g., unit and component).

Page 5: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Definition of White-Box Testing

• Testing based on analysis of internal logic(design, code, etc.). (But expected results still come from requirements.)

• Also know as structural testing.

• White-box testing concerns techniques for designing tests; it is not a “level” of testing.

• White-box testing techniques apply primarily to lower levels of testing (e.g., unit and component).

Page 6: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

White-Box Testing Topics

• Logic coverage (lecture I)

• Dataflow coverage (lecture II)

• Path conditions and symbolic execution (lecture III)

• Other white-box testing strategies (e.g., “fault-based testing”) (lecture IV)

Page 7: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage

• Statement: each statement executed at least once

• Branch: each branch traversed (and every entry point taken) at least once

• Condition: each condition True at least once and False at least once

• Branch/Condition: both Branch and Condition coverage achieved

Page 8: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage

• Statement: each statement executed at least once

• Branch: each branch traversed (and every entry point taken) at least once

• Condition: each condition True at least once and False at least once

• Branch/Condition: both Branch and Condition coverage achieved

Page 9: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage

• Statement: each statement executed at least once

• Branch: each branch traversed (and every entry point taken) at least once

• Condition: each condition True at least once and False at least once

• Branch/Condition: both Branch and Condition coverage achieved

Page 10: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage

• Statement: each statement executed at least once

• Branch: each branch traversed (and every entry point taken) at least once

• Condition: each condition True at least once and False at least once

• Branch/Condition: both Branch and Condition coverage achieved

(cont’d)

Page 11: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage (cont’d)

• Compound Condition: all combinations of condition values at every branch statement covered (and every entry point taken)

• Path: all program paths traversed at least once

Page 12: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Types of Logic Coverage (cont’d)

• Compound Condition: all combinations of condition values at every branch statement covered (and every entry point taken)

• Path: all program paths traversed at least once

Page 13: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Pseudocode and Control Flow Graphs

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

“nodes”

“edges”

Page 14: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Statement Coverage

• Statement Coverage requires that each statement will have been executed at least once.

• Simplest form of logic coverage.

• Also known as Node Coverage.

• What is the minimum number of test cases required to achieve statement coverage for the program segment given below?

Page 15: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Statement Coverage

• Statement Coverage requires that each statement will have been executed at least once.

• Simplest form of logic coverage.

• Also known as Node Coverage.

• What is the minimum number of test cases required to achieve statement coverage for the program segment given below?

Page 16: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Statement Coverage

• Statement Coverage requires that each statement will have been executed at least once.

• Simplest form of logic coverage.

• Also known as Node Coverage.

• What is the minimum number of test cases required to achieve statement coverage for the program segment given below?

Page 17: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Statement Coverage

• Statement Coverage requires that each statement will have been executed at least once.

• Simplest form of logic coverage.

• Also known as Node Coverage.

• What is the minimum number of test cases required to achieve statement coverage for the program segment given below?

Page 18: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Page 19: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 20: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 21: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 22: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 23: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 24: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 25: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

How many test cases required for Statement Coverage?

input(Y)

if (Y<=0) then

Y := −Y

end_if

while (Y>0) do

input(X)

Y := Y-1

end_while

Claim: only 1 test case is required.

Page 26: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage

• Branch Coverage requires that each branch will have been traversed, and that every program entry point will have been taken, at least once.

• Also known as Edge Coverage.

(cont’d)

Page 27: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• Why “…and that every program entry point will have been taken, at least once”?

Page 28: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• Why “…and that every program entry point will have been taken, at least once”?

Page 29: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• Why “…and that every program entry point will have been taken, at least once”?

(cont’d)

Page 30: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Page 31: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Possible relationships:

1. None.

2. Statement Coverage subsumes Branch Coverage (“statement => branch”).

3. Branch Coverage subsumes Statement Coverage (“branch => statement”).

4. Both (2) and (3) (i.e., they are equivalent)

Page 32: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Possible relationships:

1. None.

2. Statement Coverage subsumes Branch Coverage (“statement => branch”).

3. Branch Coverage subsumes Statement Coverage (“branch => statement”).

4. Both (2) and (3) (i.e., they are equivalent)

Page 33: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Possible relationships:

1. None.

2. Statement Coverage subsumes Branch Coverage (“statement => branch”).

3. Branch Coverage subsumes Statement Coverage (“branch => statement”).

4. Both (2) and (3) (i.e., they are equivalent)

Page 34: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Possible relationships:

1. None.

2. Statement Coverage subsumes Branch Coverage (“statement => branch”).

3. Branch Coverage subsumes Statement Coverage (“branch => statement”).

4. Both (2) and (3) (i.e., they are equivalent)

Page 35: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch Coverage (cont’d)

• What is the relationship between Statement and Branch Coverage?

Possible relationships:

1. None.

2. Statement Coverage subsumes Branch Coverage (“statement => branch”).

3. Branch Coverage subsumes Statement Coverage (“branch => statement”).

4. Both (2) and (3) (i.e., they are equivalent)

Page 36: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “statement => branch” ???

Min. number of cases required for Statement Coverage?

Min. number of cases required for Branch Coverage?

Page 37: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “statement => branch” ???

Min. number of cases required for Statement Coverage?

Min. number of cases required for Branch Coverage?

1

Page 38: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “statement => branch” ???

Min. number of cases required for Statement Coverage?

Min. number of cases required for Branch Coverage?

1

2

Page 39: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “statement => branch” ???

Min. number of cases required for Statement Coverage?

Min. number of cases required for Branch Coverage?

1

2

Therefore, Statement Coverage does NOTsubsume Branch Coverage.

Page 40: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “branch => statement” ???

• Normally, YES…

Page 41: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “branch => statement” ???

• Normally, YES… in the absence of “DEAD CODE”.

DEAD CODE is not reachable via any executable program path.

(cont’d)

Page 42: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Does “branch => statement” ???

• If a program has "dead (i.e., unreachable) code", then "statement coverage" is unachievable. (We would need to modify the program in order to bring the dead code back to “life”.)

• Bottom line: we will always assume the nominal case of “no dead code" unless explicitly stated otherwise. Under this assumption, Branch Coverage does indeed subsume Statement Coverage.

Page 43: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage

• A branch predicate may have more than one condition.

input(X,Y)if (Y<=0) or (X=0) then

Y := -Yend_ifwhile (Y>0) and (not EOF) do

input(X)Y := Y-1

end_while

(cont’d)

Page 44: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

• Condition Coverage requires that each condition will have been True at least once and False at least once.

• What is the relationship between Branch and Condition Coverage?

Page 45: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

• Condition Coverage requires that each condition will have been True at least once and False at least once.

• What is the relationship between Branch and Condition Coverage?

(cont’d)

Page 46: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 1 T F ?

test 2 F F ?

Page 47: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 1 T F true

test 2 F F ?

Page 48: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 1 T F true

test 2 F F false

Page 49: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 1 T F true

test 2 F F false

Page 50: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 1 T F true

test 2 F F false

Branch Coverage => Condition Coverage

Page 51: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 3 T F ?

test 4 F T ?

Page 52: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 3 T F true

test 4 F T ?

Page 53: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 3 T F true

test 4 F T true

Page 54: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 3 T F true

test 4 F T true

Page 55: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Condition Coverage (cont’d)

if A or B thens1

elses2

end_if_then_else

A B Branch

test 3 T F true

test 4 F T true

Condition Coverage => Branch Coverage

Page 56: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch/Condition Coverage

• Branch/Condition Coverage requires that both Branch AND Condition Coverage will have been achieved.

• Therefore, Branch/Condition Coverage subsumes both Branch Coverage and Condition Coverage.

Page 57: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Branch/Condition Coverage

• Branch/Condition Coverage requires that both Branch AND Condition Coverage will have been achieved.

• Therefore, Branch/Condition Coverage subsumes both Branch Coverage and Condition Coverage.

Page 58: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage

• What if the compiler generates code that masks the evaluation of conditions?

• That is, suppose

if (A) or (y/x=5) then...

is compiled in such a way that if A is true, y/x=5 will not be evaluated.

(cont’d)

Page 59: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

• Compound Condition Coverage requires that all combinations of condition values at every branch statement will have been covered, and that every entry point will have been taken, at least once.

• Also know as Multiple Condition Coverage.

• Subsumes Branch/Condition Coverage, regardless of the order in which conditions are evaluated.

Page 60: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

• Compound Condition Coverage requires that all combinations of condition values at every branch statement will have been covered, and that every entry point will have been taken, at least once.

• Also know as Multiple Condition Coverage.

• Subsumes Branch/Condition Coverage, regardless of the order in which conditions are evaluated.

Page 61: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

• Compound Condition Coverage requires that all combinations of condition values at every branch statement will have been covered, and that every entry point will have been taken, at least once.

• Also know as Multiple Condition Coverage.

• Subsumes Branch/Condition Coverage, regardless of the order in which conditions are evaluated.

(cont’d)

Page 62: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

input(X,Y)

if (Y<=0) or (X=0) then

Y := -Y

end_if

Combinations of condition values: TT, TF, FT, FF

(cont’d)

Page 63: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

• In general, how many different combinations of condition values must be considered when a branch predicate has N conditions?

Page 64: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Compound Condition Coverage (cont’d)

• In general, how many different combinations of condition values must be considered when a branch predicate has N conditions?

2N

Page 65: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage

• Path Coverage requires that all program paths will have been traversed at least once.

• Often described as the “strongest” form of logic coverage. (Is it stronger than Compound Condition Coverage?)

• Path Coverage is usually impossible when loops are present. (How many test cases would be required to cover all paths in the example below?)

Page 66: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage

• Path Coverage requires that all program paths will have been traversed at least once.

• Often described as the “strongest” form of logic coverage. (Is it stronger than Compound Condition Coverage?)

• Path Coverage is usually impossible when loops are present. (How many test cases would be required to cover all paths in the example below?)

Page 67: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage

• Path Coverage requires that all program paths will have been traversed at least once.

• Often described as the “strongest” form of logic coverage. (Is it stronger than Compound Condition Coverage?)

• Path Coverage is usually impossible when loops are present. (How many test cases would be required to cover all paths in the example below?)

(cont’d)

Page 68: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage (cont’d)

for I = 1 to 30 doinput(X,Y)if (Y<=0) then

if (X<=0) thenY := -X

elseY:=-Y

end_if_elseelse

Y := X+Yend_if_else

end_for_do

repeat 29

times

Page 69: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage (cont’d)

3 paths

3 paths

3 X 3 = 9 paths

Page 70: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage (cont’d)

repeat 29

times3 X 3 X…X 3

= 3 paths30

(cont’d)

Page 71: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Path Coverage (cont’d)

• Various strategies have been developed for identifying useful subsets of paths for testing when Path Coverage is impractical:

– Loop Coverage,

– Basis Paths Coverage, and

– Dataflow Coverage (Lecture 8).

Page 72: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage

• Loop Coverage requires that the body of loops be executed 0, 1, 2, t, max, and max+1 times, where possible.

Page 73: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage

• Loop Coverage requires that the body of loops be executed 0, 1, 2, t, max, and max+1 times, where possible.

• Rationale:

– 0: Is some action taken in the body that must also be taken when the body is not executed?

– 1: Check lower bound on number of times body may be executed.

Page 74: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage

• Loop Coverage requires that the body of loops be executed 0, 1, 2, t, max, and max+1 times, where possible.

• Rationale:

– 0: Is some action taken in the body that must also be taken when the body is not executed?

– 1: Check lower bound on number of times body may be executed.

Page 75: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage

• Loop Coverage requires that the body of loops be executed 0, 1, 2, t, max, and max+1 times, where possible.

• Rationale:

– 0: Is some action taken in the body that must also be taken when the body is not executed?

– 1: Check lower bound on number of times body may be executed.

(cont’d)

Page 76: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage (cont’d)

• Rationale: (cont’d)

– 2: Check loop re-initialization.

– t: Check typical number of iterations.

– max: Check upper (valid) bound on number of times body may be executed.

– max+1: If the maximum can be exceeded, what behavior results?

Page 77: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage (cont’d)

• Rationale: (cont’d)

– 2: Check loop re-initialization.

– t: Check typical number of iterations.

– max: Check upper (valid) bound on number of times body may be executed.

– max+1: If the maximum can be exceeded, what behavior results?

Page 78: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage (cont’d)

• Rationale: (cont’d)

– 2: Check loop re-initialization.

– t: Check typical number of iterations.

– max: Check upper (valid) bound on number of times body may be executed.

– max+1: If the maximum can be exceeded, what behavior results?

Page 79: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Loop Coverage (cont’d)

• Rationale: (cont’d)

– 2: Check loop re-initialization.

– t: Check typical number of iterations.

– max: Check upper (valid) bound on number of times body may be executed.

– max+1: If the maximum can be exceeded, what behavior results?

Page 80: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Basis Paths Coverage

• A coverage criterion associated with McCabe’s Structured Testing.

• Based on idea of identifying a “spanning” (i.e., basis) set of paths for a program’s “path space.”

• The number, C, of such paths is equal to the number of (2-way) branch statements in the program + 1. (This is also the number of enclosed regions in the program graph + 1.)

Page 81: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Basis Paths Coverage

• A coverage criterion associated with McCabe’s Structured Testing.

• Based on idea of identifying a “spanning” (i.e., basis) set of paths for a program’s “path space.”

• The number, C, of such paths is equal to the number of (2-way) branch statements in the program + 1. (This is also the number of enclosed regions in the program graph + 1.)

Page 82: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Spanning vectors in 3n-space

A

A = (x, y, z) = x (1, 0, 0) + y (0, 1, 0) + z (0, 0, 1)

X-coordinate

Page 83: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Basis Paths Coverage

• A coverage criterion associated with McCabe’s Structured Testing.

• Based on idea of identifying a “spanning” (i.e., basis) set of paths for a program’s “path space.”

• The number, C, of such paths is equal to the number of (2-way) branch statements in the program + 1. (This is also the number of enclosed regions in the program graph + 1.)

(cont’d)

Page 84: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Basis Paths Coverage (cont’d)

• C is what McCabe calls the Cyclomatic Complexity of a program.

• Any C distinct, simple program paths that provide branch coverage also form a basis set of paths. (In a simple program path, while loop bodies are executed at most once and repeat-until loop bodies are executed at most twice.)

Page 85: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Basis Paths Coverage (cont’d)

• C is what McCabe calls the Cyclomatic Complexity of a program.

• Any C distinct, simple program paths that provide branch coverage also form a basis set of paths. (In a simple program path, while loop bodies are executed at most once and repeat-until loop bodies are executed at most twice.)

Page 86: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 1

if a then s1else if b then s2

else if c then s3else s4end_if_then_else

end_if_then_elseend_if_then_else

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

Page 87: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 1

if a then s1else if b then s2

else if c then s3else s4end_if_then_else

end_if_then_elseend_if_then_else

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___4

Page 88: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 1

if a then s1else if b then s2

else if c then s3else s4end_if_then_else

end_if_then_elseend_if_then_else

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___4

1

2

3

Page 89: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 1

if a then s1else if b then s2

else if c then s3else s4end_if_then_else

end_if_then_elseend_if_then_else

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___4

1

2

3

4

Page 90: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 1

if a then s1else if b then s2

else if c then s3else s4end_if_then_else

end_if_then_elseend_if_then_else

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___4

1

2

3

4 4

Page 91: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 2

if a thens1

end_if_thenif b then

s2end_if_thenif c then

s3end_if_then

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

Page 92: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 2

if a thens1

end_if_thenif b then

s2end_if_thenif c then

s3end_if_then

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___8

Page 93: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 2

if a thens1

end_if_thenif b then

s2end_if_thenif c then

s3end_if_then

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___8

1

2

3

Page 94: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 2

if a thens1

end_if_thenif b then

s2end_if_thenif c then

s3end_if_then

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___8

1

2

3

4

Page 95: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 2

if a thens1

end_if_thenif b then

s2end_if_thenif c then

s3end_if_then

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___8

1

2

3

4 2

Page 96: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 3

while a do

if b then s1

else s2

end_if_then_else

end_while

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

Page 97: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 3

while a do

if b then s1

else s2

end_if_then_else

end_while

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

Page 98: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 3

while a do

if b then s1

else s2

end_if_then_else

end_while

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

1

2

Page 99: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 3

while a do

if b then s1

else s2

end_if_then_else

end_while

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

1

2

3

Page 100: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Example 3

while a do

if b then s1

else s2

end_if_then_else

end_while

Paths: ___ Basis Paths: ___ Cases for branch coverage: ___

1

2

3 1

Page 101: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

In General…

Number of program Paths

Number of Basis Paths

Number of test cases required for branch coverage

Path CoverageBasis Paths Coverage Branch Coverage=> =>

Page 102: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Exercise

Prove that Path and Compound Condition Coverage are independent.

(Hint: consider the proof that Branch and Condition Coverage are independent.)

Page 103: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

Coming Up Next…

• In the next lecture we consider a family of path selection criteria based on the idea that program paths along which variables are defined and then used should be covered.

• The strategy is popularly known as Dataflow Coverage.

Page 104: White-Box Testing Techniques I › ... › lec_notes › 07.white1_lect.pdf · 2018-01-31 · Definition of White-Box Testing •Testing based on analysis of internal logic (design,

White-Box Testing Techniques I

Prepared by

Stephen M. Thebaut, Ph.D.

University of Florida

Software Testing and Verification

Lecture 7