Software Testing Ch3-1 White Box Testing
Software Testing Ch3-1 White Box Testing
LOGO
Contents
White-Box Testing
● 3.1 Basic Concepts
● 3.2 Logic Coverage
Chapter 3 ● 3.3 Control Flow Graph
● 3.4 Basis Path Testing
● 3.5 Loop Testing
● 3.6 Data Flow Testing
● 3.7 A Comparison of White-box Testing and
Black-box Testing
3.1 Basic Concepts
● White-box testing can examine how the
internal mechanism of a program works.
● It focuses on the internal structure or
implementation, instead of the functionalities (Black-
box testing).
● Software engineers should design test cases based
on the implementation of the program.
3.1 Basic Concepts
● White-box testing
● It indicates that you have full visibility of the
internal workings of the software product,
especially for the logic and the structure of the
code.
● It is also known as structural testing, clear box
testing, and glass box testing.
3.1 Basic Concepts
● White-box testing: static & dynamic.
● Static white-box testing methods:
● code inspection
● structure analysis, etc.
The first No No No No
The second Yes Yes No No
The third Yes Yes Yes No
The fourth Yes Yes Yes Yes
3.2 Logic Coverage
a
● Logic coverage The ability of b
F T
c
(A>1) ∧(B=0)
finding errors:
● Statement coverage weak strong
● Decision coverage x=x/A
● Condition coverage
● Condition/decision coverage F T
● Condition combination coverage
d e
(A=2) ∨(x>1)
● Shortcoming:
【 2, 0, 3 】 covers ce 【 1, 1, 1 】 covers bd
or
【 3, 0, 3 】 covers cd 【 2, 1, 1 】 covers be
If x>1 is written wrongly as x>0 , test case
can’t find this problem. For example, if x>1 is
written wrong as x<1, using the above case
【 2,1,1 】 (be) will get the same result.
Decision Coverage cannot detect the wrong conditions in judgment
3.2 Logic Coverage—Condition coverage
● The goal is to test all possible values of each
condition at least once.
● For the first judgment
● Condition A > 1 true value is T1 , false value is !T1
● Condition B = 0 true value is T2 , false value is !T2
● For the second judgment
● Condition A = 2 true value is T3 , false value is !T3
● Condition X > 1 true value is T4 , false value is !T4
3.2 Logic Coverage—Condition Coverage
② A > 1, B≠0 as T1!T2
③ A≯1, B = 0 as !T1T2
④ A≯1, B≠0 as !T1!T2
⑤ A = 2, X > 1 as T3T4
⑥ A = 2, X≯1 as T3!T4
⑦ A≠2, X > 1 as !T3T4
⑧ A≠2, X≯1 as !T3!T4
3.2 Logic Coverage—Condition Combination
Coverage
Test Path Coverage Coverage Combination
case condition branch coverage No.
(2, 0, 3) ace(L1) T1 T2 T3 T4 c,e ①⑤
(2, 1, 1) abe(L3) T1 !T2 T3 !T4 b,e ②⑥
Test Condition
No. path
case coverage
1 (2, 0, 3) ace(L1) T1T2T3T4
2 (1, 0, 1) abd(L2) !T1!T2!T3!T4
3 (2, 1, 1) abe(L3) !T1!T2!T3T4
4 (3, 0, 3) acd(L4) T1T2!T3!T4
3.2 Logic Coverage
● Complete coverage
No. Test case path Condition coverage
1 (2, 0, 3) ace(L1) ①⑤
2 (1, 0, 1) abd(L2) ④⑧
3 (2, 1, 1) abe(L3) ②⑥
4 (3, 0, 3) acd(L4) ①⑧
5 (1, 0, 3) abe(L3) ③⑦
3.2 Logic Coverage—Path Coverage
● In many scenarios, it is difficult to enumerate
all possible paths.
• For multiple choices
and nesting cycle of the
procedure, the number
of different possible
paths is astronomical.
M1
• When the cycle≤20
times, the number of D1
D2
different paths is 5 .
20
D3 D4
• If the implementation
M5
time of each path is 1 M2 M3 M4 M6
ms , it will take M7
3170years to test all
D5
paths.
One optimization is to transfer “while-statement” into
“if-else” statement, i.e., the loop body is executed only
once.
3.2 Logic Coverage — Summary
● Relationships
path
condition
combination
decision—condition
decision condition
stateme
nt
LOGO