White Box Basics – Part 1
Introduction to Coverage
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
What is White Box Testing ?
White Box Testing is a stupid expression
You cannot see what’s in a white box
It’s as obscure as a black box
Glass Box Testing would be better
Alas, “White Box” is a household world
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
What is White Box Testing ?
If you know the structure of the program,
you can design tests to make sure that there
is a certain coverage of
Statements
Branches
Paths
Conditions
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
What is White Box Testing ?
CAUTION
White Box will not show you if the program does
work along the PROJECT REQUIREMENTS
It will show you if it does what the DEVELOPER
wanted !
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
Let’s start with a
very
simple structure.
I call this a
Mickey Mouse
structure
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
First, we will want to make sure
that all the operations in the
program will be executed when
we run our
UNIT TEST
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
Testcase #1 will execute operation-A
condition-1 has to be TRUE to reach the operation
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
Testcase #2 will execute operation-B
condition-1 has to be FALSE to reach the operation
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
Testcase #1: condition-1 is TRUE
Testcase #2: condition-1 is FALSE
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
Testcase #3 will execute operation-C
then
condition-2 has to be TRUE to reach the operation
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
3 Testcases
???
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
The upper and the lower part of the program are completely independent
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE does not matter
#2 FALSE does not matter
#3 does not matter TRUE
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE does not matter
#3 does not matter not needed anymore
2 test cases will be enough for our purpose
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE does not matter
“does not matter” is a silly condition
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE TRUE
“does not matter” is a silly condition
Let’s replace it by “TRUE”
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE TRUE
What did we cover with our two
test cases so far ?
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Statement Coverage
if condition-1 if condition-1
then then
operation-A operation-A
else else
operation-B operation-B
endif endif
if condition-2 if condition-2
then then
operation-C operation-C
endif endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Statement Coverage
Anweisungsüberdeckung
if condition-1 if condition-1
then then
operation-A operation-A
else else
operation-B operation-B
endif endif
if condition-2 if condition-2
then then
operation-C operation-C
endif endif
We have covered 100 % of the statements
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Statement Coverage
Anweisungsüberdeckung
We have covered 100 % of the
statements
Is this a strong coverage ?
NOT REALLY
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
There is an
uncovered branch
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE TRUE
There is an
uncovered
condition
There is an
uncovered branch
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE does not matter
Originally, we said condition-2
“does not matter”
Let’s set it to “FALSE”
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
if condition-1
then
operation-A
else
operation-B
endif
if condition-2
then
operation-C
endif
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Branch Coverage
Zweigüberdeckung
Now we have covered 100 % of the branches
Is this a strong coverage ?
NOT SO BAD
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE FALSE
We also managed to obtain a situation
where we tested for TRUE and FALSE
for each of our conditions
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Condition Coverage
Bedingungsüberdeckung
We have covered 100 % of the conditions
Is this a strong coverage ?
IT DEPENDS…
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Condition Coverage
Bedingungsüberdeckung
There are different types of conditions
If we have only simple conditions with
operators like <, >, =, and similar
relations we are talking about
ATOMIC CONDITIONS
ATOMARE BEDINGUNGEN
NO BOOLEAN EXPRESSIONS !
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Condition Coverage
Bedingungsüberdeckung
Let’s assume that the conditions
In our example are atomic, no NOT, AND,
OR, XOR, only really simple expressions.
Then we are talking about
BRANCH CONDITION TESTING
EINFACHE BEDINGUNGÜBERDECKUNG
In this case 100% is not bad at all !
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
Can we do more ?
Let’s have a look !
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
We have covered
two of the
possible paths
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
TESTCAS condition-1 condition-2
#1E TRUE TRUE
#2 FALSE FALSE
We have covered two of the possible combinations of the conditions
It’s obvious that there are 2² = 4
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
It’s obvious that there are 2² = 4
TESTCAS condition-1 condition-2
E
#1 TRUE TRUE
#2 FALSE FALSE
#3 TRUE FALSE
#4 FALSE TRUE
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
#1
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
#2
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
#3
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
#4
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Path Coverage
Pfadüberdeckung
We have covered 100 % of the paths
Is this a strong coverage ?
OH YES IT IS
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – Simple Structure
What did we learn in this session ?
We found out about
Statement Coverage – Anweisungsüberdeckung
Branch Coverage – Zweigüberdeckung
Path Coverage – Pfadüberdeckung
We are not so sure about Branch Conditions…
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – HOMEWORK
Apply this lesson
to the structure
on the left
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – HOMEWORK
Which Coverage is stronger ?
Branch
Statement
Path
Sort them like:
a>b>c
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
COVERAGE – HOMEWORK
Please be aware that understanding
those things will be extremely
important for:
2. Designing Tests
3. Following up the future sessions
4. Any type of certifications
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
DR. WOLFGANG J. SCHNEIDER GMBH
International Information Technology Consultants
Professional Testing Solutions
Telecommunications and Utility Billing Systems
Euro Preparation for Companies in New EU Member Countries
EDIFACT – DATANORM – ELDANORM – ETIM Interfaces
Data Exchange with Banks and Credit Card Companies
Total Quality Management – Good Manufacturing Practices
IT Service Management - IT Infrastructure Library (ITIL)
Knowledge Management Solutions
IT Fitness for GAAP – IAS – FASB
Balanced Scorecard
Dr. Wolfgang J. Schneider - Start
www.drschneider.at
(c) Dr.Wolfgang J. Schneider 2003 - 2008 - www.drschneider.at
Take Advantage of 30+ Years of IT Experience !