0% found this document useful (0 votes)
86 views

8 - White Box Testing I

The document discusses various white-box testing techniques including statement coverage, branch coverage, condition coverage, and modified condition/decision coverage. It explains each technique, provides examples, and compares their strengths and weaknesses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
86 views

8 - White Box Testing I

The document discusses various white-box testing techniques including statement coverage, branch coverage, condition coverage, and modified condition/decision coverage. It explains each technique, provides examples, and compares their strengths and weaknesses.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 44

White-box testing techniques

Dr. Durga Prasad Mohapatra


Professor, Dept. of CSE
N.I.T Rourkela

1
White-box Testing
 Designing white-box test cases:
◦ Requires knowledge about the
internal structure of software.
◦ White-box testing is also called
structural testing.
◦ In this unit we will study white-box testing.

2
White-Box Testing Methodologies
 There exist several popular white-box testing
methodologies:
◦ Statement coverage
◦ Branch coverage
◦ Condition coverage
◦ MC/DC coverage
◦ Path coverage
◦ Data flow-based testing
◦ Mutation testing

3
Statement Coverage
 Statement
coverage
methodology:
◦ Design test cases so that every
statement in the program is
executed at least once.

4
Statement Coverage
 The principal idea:
◦ Unless a statement is executed,
◦ We have no way of knowing if
an error exists in that
statement.

5
Statement Coverage Criterion
 Observing that a statement behaves
properly for one input value:
◦ No guarantee that it will behave
correctly for all input values.

6
Statement Testing
 Coverage measurement:
# executed statements
# statements

 Rationale: a fault in a statement can only


be revealed by executing the faulty
statement

7
Example
int f1(int x, int y){
1 while (x != y){
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5}
6 return x; }

8
Euclid's GCD Algorithm
 Bychoosing the test set
{(x=3,y=3),(x=4,y=3), (x=3,y=4)}
◦ All statements are executed at
least once.

9
Branch Coverage
 Test cases are designed such
that:
◦ different branch conditions
given true and false values in turn.

10
Branch Coverage
 Branchtesting guarantees
statement coverage:
◦ A stronger testing compared to
the statement coverage-based
testing.

11
Stronger Testing

 Test
cases are a superset of a
weaker testing:
◦ A stronger testing covers at least all
the elements covered by a weaker
testing.

12
Stronger, Weaker, and
Complementary Testing
Complementary

Weaker

13
Example
int f1(int x,int y){
1 while (x != y){
2 if (x>y) then
3 x=x-y;
4 else y=y-x;
5}
6 return x; }

14
Example
 Test cases for branch coverage
can be:
 {(x=3,y=3),(x=3,y=2), (x=4,y=3),
(x=3,y=4)}

15
Branch Testing
 Adequacy criterion: Each branch (edge in
the CFG) must be executed at least once
 Coverage:
# executed branches
# branches

16
Statements vs Branch Testing
 Traversing
all edges of a graph causes all
nodes to be visited
◦ So test suites that satisfy the branch adequacy
criterion for a program P also satisfy the
statement adequacy criterion for the same
program
 The converse is not true
◦ A statement-adequate (or node-adequate) test
suite may not be branch-adequate (edge-
adequate) 17
Condition Coverage
 Test cases are designed such that:
◦ Each component of a composite
conditional expression
 Given both true and false values.

18
Branch vs Condition testing
 Condition testing:
◦ Stronger testing than branch
testing.
 Branch testing:
◦ Stronger than statement
coverage testing.
19
Branch vs Condition testing
 Branch testing is the simplest
condition testing strategy:
◦ Compound conditions appearing in
different branch statements
are given true and false values.

20
Multiple Condition Coverage

 Multiple condition coverage reports


whether every possible combination
of Boolean sub-expressions occurs.
 The test cases required for full
multiple condition coverage of a
condition are essentially given by the
logical operator truth table for the
condition.
21
Multiple Condition Coverage cont …

 Test cases are designed such that:


each component of a composite
conditional expression
 given both true and false values.

22
Example

 Consider the conditional expression


((c1.and.c2).or.c3):
 Each of c1, c2, and c3 are exercised at
least once,
i.e. given true and false values.

23
Multiple Condition Coverage Examples
if(A && B) // condition 1
F1();
else
F2();
if(C || D) // condition 2
F3()
else
F4();

Test Cases for MCC:

For condition 1 For condition 2


A=T, B=T C=T, D=T
A=T, B=F C=T, D=F
A=F, B=T C=F, D=T
A=F, B=F C=F, D=F 24
MCC Testing Adequacy Criterion

 Adequacy criterion: Each basic condition must be


executed at least once
 Coverage:
# truth values taken by all basic conditions
2 * # basic conditions

25
Branch Testing vs MCC Testing

 Multiple Condition Coverage testing:


Stronger testing than branch testing.
 Branch testing:
Stronger than statement coverage testing.

26
Need of a Feasible Testing Technique

 Consider a boolean expression having n


components:
n
For condition coverage we require 2 test
cases. (example in next slide)
 Condition coverage-based testing technique:
Practical only if n (the number of
component conditions) is small.

27
Consider: if (a || b && c) then …
Test a b c

(1) T T T

(2) T T F

(3) T F T
MCC
(4) T F F

(5) F T T
Exponential in
(6) T T F
the number of
(7) F F T
basic conditions
(8) F F F
Modified condition/decision
(MC/DC)
 Motivation: Effectively test important
combinations of conditions, without
exponential blowup in test suite size
◦ “Important” combinations means: Each basic condition
shown to independently affect the outcome of each
decision
 Requires:
◦ For each basic condition C, two test cases,
◦ values of all evaluated conditions except C are the
same
◦ compound condition as a whole evaluates to true for
one and false for the other

29
What is MC/DC?
 MC/DC stands for Modified Condition /
Decision Coverage
 A kind of Predicate Coverage technique
◦ Condition: Leaf level Boolean expression.
◦ Decision: Controls the program flow.
 Main idea: Each condition must be shown to
independently affect the outcome of a decision,
i.e. the outcome of a decision changes as a
result of changing a single condition.
30
31
Condition Coverage

• Every condition in the decision has


taken all possible outcomes at least
once.

If ((a) && (b) || (c)) then…



true false true false true false

32
MC/DC Coverage
 Every condition in the decision
independently affects the decision’s
outcome.

If ((a) && (b) || (c)) then…

true false true false

Change the value of each condition


individually while keeping all other
conditions constant.

33
MC/DC: linear complexity
• N+1 test cases for N basic conditions

(((a || b) && c) || d) && e

Test a b c d e outcome
Case
(1) true -- true -- true true
(2) false true true -- true true
(3) true -- false true true true
(6) true -- true -- false false
(11) true -- false false -- false
(13) false false -- false -- false

• Underlined values independently affect the output of the decision


• Required by the RTCA/DO-178B standard

34
Comments on MC/DC
 MC/DC is
◦ basic condition coverage (C)
◦ branch coverage (DC)
◦ plus one additional condition (M):
every condition must independently affect the decision’s
output
 It is subsumed by compound conditions and
subsumes all other criteria discussed so far
◦ stronger than statement and branch coverage
 A good balance of thoroughness and test size (and
therefore widely used)

35
Example
If (A && B) then…
(1) create truth table for conditions.
(2) Extend truth table so that it indicated which test
cases can be used to show the independence of each
condition.

A B Result
Number A B Result A B
T T T
1 T T T 3 2
T F F
2 T F F 1
F T F 3 F T F 1

F F F 4 F F F

36
Example cont …

 Show independence of A:
Number A B Result A B
 Take 1 + 3
1 T T T 3 2  Show independence of B:
 Take 1 + 2
2 T F F 1  Resulting test cases are
 1+2+3
3 F T F 1
 (T , T) + (T , F) + (F , T)
4 F F F

37
More advanced example
If (A && (B || C)) then…

Number A B C Result A B C
1 T T T T 5
2 T T F T 6 4
3 T F T T 7 4
4 T F F F 2 3
5 F T T F 1
6 F T F F 2
7 F F T F 3
8 F F F F

38
More advanced example contd..
Note: We want to determine the MINIMAL set
of test cases
Here:
• {2,3,4,6}
• {2,3,4,7}
Non-minimal set is:
• {1,2,3,4,5}

39
Where does it fit in?
 The MC/DC criterion is much Multiple-condition all paths
stronger than the condition/decision
coverage criterion, but the number
of test cases to achieve the MC/DC
criterions still varies linearly with the Modified condition/decision all-du-paths
number of conditions n in the
decisions.
 Much more complete coverage Condition/Decision all uses
than condition/decision coverage,
but
 at the same time it is not terribly Decision reach
costly in terms of number of test
cases.
Statement Condition

40
Comparison of different coverage
based Testing Strategies

41
Summary
 Discussed white-box test case design
using:
◦ Statement coverage technique
◦ Branch coverage technique
◦ Condition coverage technique
◦ MC/DC technique

42
References
1. Rajib Mall, Fundamentals of Software
Engineering, (Chapter – 10), Fifth Edition, PHI
Learning Pvt. Ltd., 2018.
2. Naresh Chauhan, Software Testing: Principles
and Practices, (Chapter – 5), Second Edition,
Oxford University Press, 2016.
Thank You

44

You might also like