SlideShare a Scribd company logo
White Box Testing 
Len Schroath 
September 18, 2007
Agenda 
• White-box vs Black-box 
• Program Flow Controls 
• White-box Test Methods 
• Exercises 
• Complexity 
• Q&A
What is White-box Testing? 
• Looking at the internal structure of a program 
and deriving test cases based on the logic or 
control flow. 
• Test cases can be designed to reach every 
branch in the code and to exercise each 
condition 
• Typically done during unit testing 
• Also known as: 
– Structural Testing 
– Glass-Box Testing
What is Black-box Testing? 
• Looking at the program from an external 
point of view and deriving test cases 
based on the specification. 
• The only criteria upon which the program 
is judged is if it produces the correct 
output for a given input.
Why Do Both? 
Black-box 
• Impossible to write a test 
case for every possible 
set of inputs and outputs 
• Some of the code may 
not be reachable without 
extraordinary measures 
• Specifications are not 
always complete 
White-box 
• Does not address the 
question of whether or 
not the program matches 
the specification 
• Does not tell you if all of 
the functionality has been 
implemented 
• Does not discover 
missing program logic
Basic Program Flow Controls 
• IF 
• IF-Then-Else 
• FOR 
• While 
• Do-While 
• Case
IF Diagram
IF-THEN-ELSE Diagram
FOR or WHILE Diagram
DO-WHILE Diagram
CASE Diagram
Example Code Fragment
Example Control Flow Graph 
Source: The Art of Software Testing – Glenford Myers
Exercise #1 
• int main (int argc, char *argv[]) 
• { 
• /* Process CTRL-C Interrupts */ 
• signal(SIGINT,catcher); 
• if (validate_command_line(argc)) return(1); 
• if (job_initialize(argv)) return(1); 
• processTestList(); /* Process all testCases in 
TestList */ 
• displayResults(); 
• fprintf(stdout,"Test Completen"); 
• job_termination(); 
• return(0); 
• } /* main */ Can you diagram 
this code?
Did You Get Something Like This?
Exercise #2 
/* Attempt Statusreadback - log SRB data to logFile */ 
int process_srb(void) 
{ 
int srb_count = 0; 
do 
{ 
srb_count = read_printer(srb_in); 
} while (!srb_count); 
fprintf(logFile,"%sn",srb_in); 
return(srb_count); 
} /* process_srb */ 
/* Write String to Printer via Parallel or Serial port */ 
void write_printer (char *outputline) 
{ 
if (strstr(printertype,"PAR") != NULL) 
{ 
bwrite_parST(printerport,outputline); 
} 
else if (strstr(printertype,"SER") != NULL) 
{ 
bwwrite_serial(printerport,outputline,strlen(outputline)); 
} 
else if (strstr(printertype, "FILE") !=NULL) 
{ 
fprintf(printerFile,"%s",outputline); 
} 
} /* write_printer */ 
Can you diagram 
this code?
Did You Get Something Like This?
White-box Test Methods 
• Statement Coverage 
• Decision/Branch Coverage 
• Condition Coverage 
• Decision/Condition Coverage 
• Path Coverage
Example Code Fragment 
• If ((A>1) & (B=0)) 
then Do; 
• X=X/A; 
• END; 
• If ((A==2) | (X>1)) 
then Do; 
• X=X+1; 
• END; 
• END; 
Source: The Art of Software Testing – Glenford Myers
Statement Coverage 
• Exercise all 
statements at least 
once 
• How many test 
cases? 
A=2 and B=0 (ace) 
Source: The Art of Software Testing – Glenford Myers
Decision/Branch Coverage 
• Each decision has a 
true and a false 
outcome at least once 
• How many test 
cases? 
A=2 and B=0 (ace) 
A=1 and X=1 (abd) 
Source: The Art of Software Testing – Glenford Myers
Condition Coverage 
• Each condition in a 
decision takes on all 
possible outcomes at 
least once 
• Conditions: A>1, B=0, 
A=2, X>1 
• How many test cases? 
A=2, B=0, and X=4 (ace) 
A=1, B=1, and X=1 (abd) 
Source: The Art of Software Testing – Glenford Myers
Decision/Condition Coverage 
• Each condition in a decision 
takes on all possible 
outcomes at least once, and 
each decision takes on all 
possible outcomes at least 
once 
• How many test cases? 
 A=2, B=0, and X=4 (ace) 
 A=1, B=1, and X=1 (abd) 
• What about these? 
 A=1, B=0, and X=3 
 A=2, B=1, and X=1 
(abe) 
(abe)
Multiple Condition Coverage 
• Exercise all possible 
combinations of 
condition outcomes in 
each decision 
• Conditions: 
A>1, B=0 
A>1, B<>0 
A<=1, B=0 
A<=1, B<>0 
A=2, X>1 
A=2, X<=1 
A<>2, X>1 
A<>2, X<=1 
Source: The Art of Software Testing – Glenford Myers
Multiple Condition Coverage 
• How many test 
cases? 
A=2, B=0, X=4 
A=2, B=1, X=1 
A=1, B=0, X=2 
A=1, B=1, X=1 
Source: The Art of Software Testing – Glenford Myers 
(ace) 
(abe) 
(abe) 
(abd)
Path Coverage 
• Every unique path 
through the program 
is executed at least 
once 
• How many test 
cases? 
A=2, B=0, X=4 (ace) 
A=2, B=1, X=1 (abe) 
A=3, B=0, X=1 (acd) 
A=1, B=1, X=1 (abd) 
Source: The Art of Software Testing – Glenford Myers
McCabe’s Cyclomatic Complexity 
• Software metric 
• Developed by Tom McCabe (circa 1976) 
• Directly measures the number of linearly 
independent paths through a program’s 
source code, taking into account the 
various decision points 
• Independent of implementation language 
Source: Wikipedia
Calculating Complexity
Calculating Complexity
How Complex Should Code Be? 
• <10: Simple module, not much risk 
• 10-20: More Complex; moderate risk 
• 20-50: Complex; high risk 
• >50: Untestable; extremely high risk 
Source: Carnegie Mellon Software Engineering Institute
Complexity Caveats 
• As code is broken into smaller modules to 
decrease cyclomatic complexity, structural 
complexity increases 
• Some modules may have high complexity 
but are very easy to comprehend and 
easy to test 
• High complexity numbers are only an 
indicator of something to investigate
Questions?

More Related Content

PPTX
OOPs in Java
ODP
19.cobra
PDF
Intro to functional programming
PPTX
Object-Oriented Paradigm
PPTX
Ruby Programming Language - Introduction
PPTX
Association agggregation and composition
PPT
ADO.NET Entity Framework
PPT
Black box & white-box testing technique
OOPs in Java
19.cobra
Intro to functional programming
Object-Oriented Paradigm
Ruby Programming Language - Introduction
Association agggregation and composition
ADO.NET Entity Framework
Black box & white-box testing technique

What's hot (20)

PPTX
Introduction to Visual Basic 6.0 Fundamentals
PPT
Visula C# Programming Lecture 1
PPTX
JAVA PROGRAMMING
DOCX
Dominios en Base de Datos
PPTX
Threads in Java
PPTX
Java awt (abstract window toolkit)
PDF
Android Location and Maps
PDF
AndroidManifest
PPTX
Windowforms controls c#
PPTX
Levels Of Testing.pptx
PDF
Android SDK Tutorial | Edureka
PPT
Java Basics for selenium
PDF
Android Threading
PPTX
Android UI
PPT
Visual basic
PPT
Basic using of Swing in Java
PPTX
Polymorphism
PPT
android activity
PPT
Applet life cycle
PPT
SQLITE Android
Introduction to Visual Basic 6.0 Fundamentals
Visula C# Programming Lecture 1
JAVA PROGRAMMING
Dominios en Base de Datos
Threads in Java
Java awt (abstract window toolkit)
Android Location and Maps
AndroidManifest
Windowforms controls c#
Levels Of Testing.pptx
Android SDK Tutorial | Edureka
Java Basics for selenium
Android Threading
Android UI
Visual basic
Basic using of Swing in Java
Polymorphism
android activity
Applet life cycle
SQLITE Android
Ad

Viewers also liked (10)

PPTX
White Box Testing
PPT
12 white box testing-fixed
PPT
White box testing
ODP
White box ppt
PPT
White Box Testing V0.2
PPS
Lesson 2....PPT 1
PPTX
Introduction to White box testing
PDF
White Box Testing
PDF
Designing Teams for Emerging Challenges
PDF
Visual Design with Data
White Box Testing
12 white box testing-fixed
White box testing
White box ppt
White Box Testing V0.2
Lesson 2....PPT 1
Introduction to White box testing
White Box Testing
Designing Teams for Emerging Challenges
Visual Design with Data
Ad

Similar to White box testing-200709 (20)

PPT
11 whiteboxtesting
PPTX
white-box-testing.pptx
PPTX
Understanding Key Concepts and Applications in Week 11: A Comprehensive Overv...
PDF
Class9_SW_Testing_Strategies.pdf
PPTX
Java Programming Course for beginners -الدسوقي
PDF
DSR Testing (Part 1)
PPTX
1_Introduction.pptx
PPT
Code Analysis-run time error prediction
PPT
Unit 2 Unit level testing.ppt
PDF
Klee and angr
PPT
testing(2).pptjjsieieo2i33kejjskskosowwiwk
PPT
Software Engineering (Testing techniques)
PPT
Software Engineering (Testing techniques)
PDF
Introduzione allo Unit Testing
PPTX
Unit 4 testing
PPT
Dynamic Testing
PPT
New software testing-techniques
PPT
Software Testing- Principles of testing- Mazenet Solution
PPTX
Software testdesign
PPTX
AoA Lec Design of algorithm spresentation
11 whiteboxtesting
white-box-testing.pptx
Understanding Key Concepts and Applications in Week 11: A Comprehensive Overv...
Class9_SW_Testing_Strategies.pdf
Java Programming Course for beginners -الدسوقي
DSR Testing (Part 1)
1_Introduction.pptx
Code Analysis-run time error prediction
Unit 2 Unit level testing.ppt
Klee and angr
testing(2).pptjjsieieo2i33kejjskskosowwiwk
Software Engineering (Testing techniques)
Software Engineering (Testing techniques)
Introduzione allo Unit Testing
Unit 4 testing
Dynamic Testing
New software testing-techniques
Software Testing- Principles of testing- Mazenet Solution
Software testdesign
AoA Lec Design of algorithm spresentation

Recently uploaded (20)

PDF
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
PDF
737-MAX_SRG.pdf student reference guides
PDF
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
PDF
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
PDF
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
PDF
Design Guidelines and solutions for Plastics parts
PPTX
Artificial Intelligence
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
August 2025 - Top 10 Read Articles in Network Security & Its Applications
PDF
Soil Improvement Techniques Note - Rabbi
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PPTX
introduction to high performance computing
PPTX
Feature types and data preprocessing steps
PPTX
Fundamentals of Mechanical Engineering.pptx
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
EXPLORING LEARNING ENGAGEMENT FACTORS INFLUENCING BEHAVIORAL, COGNITIVE, AND ...
737-MAX_SRG.pdf student reference guides
A SYSTEMATIC REVIEW OF APPLICATIONS IN FRAUD DETECTION
BIO-INSPIRED HORMONAL MODULATION AND ADAPTIVE ORCHESTRATION IN S-AI-GPT
III.4.1.2_The_Space_Environment.p pdffdf
PREDICTION OF DIABETES FROM ELECTRONIC HEALTH RECORDS
Level 2 – IBM Data and AI Fundamentals (1)_v1.1.PDF
Design Guidelines and solutions for Plastics parts
Artificial Intelligence
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
August 2025 - Top 10 Read Articles in Network Security & Its Applications
Soil Improvement Techniques Note - Rabbi
Management Information system : MIS-e-Business Systems.pptx
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
introduction to high performance computing
Feature types and data preprocessing steps
Fundamentals of Mechanical Engineering.pptx
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS

White box testing-200709

  • 1. White Box Testing Len Schroath September 18, 2007
  • 2. Agenda • White-box vs Black-box • Program Flow Controls • White-box Test Methods • Exercises • Complexity • Q&A
  • 3. What is White-box Testing? • Looking at the internal structure of a program and deriving test cases based on the logic or control flow. • Test cases can be designed to reach every branch in the code and to exercise each condition • Typically done during unit testing • Also known as: – Structural Testing – Glass-Box Testing
  • 4. What is Black-box Testing? • Looking at the program from an external point of view and deriving test cases based on the specification. • The only criteria upon which the program is judged is if it produces the correct output for a given input.
  • 5. Why Do Both? Black-box • Impossible to write a test case for every possible set of inputs and outputs • Some of the code may not be reachable without extraordinary measures • Specifications are not always complete White-box • Does not address the question of whether or not the program matches the specification • Does not tell you if all of the functionality has been implemented • Does not discover missing program logic
  • 6. Basic Program Flow Controls • IF • IF-Then-Else • FOR • While • Do-While • Case
  • 9. FOR or WHILE Diagram
  • 13. Example Control Flow Graph Source: The Art of Software Testing – Glenford Myers
  • 14. Exercise #1 • int main (int argc, char *argv[]) • { • /* Process CTRL-C Interrupts */ • signal(SIGINT,catcher); • if (validate_command_line(argc)) return(1); • if (job_initialize(argv)) return(1); • processTestList(); /* Process all testCases in TestList */ • displayResults(); • fprintf(stdout,"Test Completen"); • job_termination(); • return(0); • } /* main */ Can you diagram this code?
  • 15. Did You Get Something Like This?
  • 16. Exercise #2 /* Attempt Statusreadback - log SRB data to logFile */ int process_srb(void) { int srb_count = 0; do { srb_count = read_printer(srb_in); } while (!srb_count); fprintf(logFile,"%sn",srb_in); return(srb_count); } /* process_srb */ /* Write String to Printer via Parallel or Serial port */ void write_printer (char *outputline) { if (strstr(printertype,"PAR") != NULL) { bwrite_parST(printerport,outputline); } else if (strstr(printertype,"SER") != NULL) { bwwrite_serial(printerport,outputline,strlen(outputline)); } else if (strstr(printertype, "FILE") !=NULL) { fprintf(printerFile,"%s",outputline); } } /* write_printer */ Can you diagram this code?
  • 17. Did You Get Something Like This?
  • 18. White-box Test Methods • Statement Coverage • Decision/Branch Coverage • Condition Coverage • Decision/Condition Coverage • Path Coverage
  • 19. Example Code Fragment • If ((A>1) & (B=0)) then Do; • X=X/A; • END; • If ((A==2) | (X>1)) then Do; • X=X+1; • END; • END; Source: The Art of Software Testing – Glenford Myers
  • 20. Statement Coverage • Exercise all statements at least once • How many test cases? A=2 and B=0 (ace) Source: The Art of Software Testing – Glenford Myers
  • 21. Decision/Branch Coverage • Each decision has a true and a false outcome at least once • How many test cases? A=2 and B=0 (ace) A=1 and X=1 (abd) Source: The Art of Software Testing – Glenford Myers
  • 22. Condition Coverage • Each condition in a decision takes on all possible outcomes at least once • Conditions: A>1, B=0, A=2, X>1 • How many test cases? A=2, B=0, and X=4 (ace) A=1, B=1, and X=1 (abd) Source: The Art of Software Testing – Glenford Myers
  • 23. Decision/Condition Coverage • Each condition in a decision takes on all possible outcomes at least once, and each decision takes on all possible outcomes at least once • How many test cases?  A=2, B=0, and X=4 (ace)  A=1, B=1, and X=1 (abd) • What about these?  A=1, B=0, and X=3  A=2, B=1, and X=1 (abe) (abe)
  • 24. Multiple Condition Coverage • Exercise all possible combinations of condition outcomes in each decision • Conditions: A>1, B=0 A>1, B<>0 A<=1, B=0 A<=1, B<>0 A=2, X>1 A=2, X<=1 A<>2, X>1 A<>2, X<=1 Source: The Art of Software Testing – Glenford Myers
  • 25. Multiple Condition Coverage • How many test cases? A=2, B=0, X=4 A=2, B=1, X=1 A=1, B=0, X=2 A=1, B=1, X=1 Source: The Art of Software Testing – Glenford Myers (ace) (abe) (abe) (abd)
  • 26. Path Coverage • Every unique path through the program is executed at least once • How many test cases? A=2, B=0, X=4 (ace) A=2, B=1, X=1 (abe) A=3, B=0, X=1 (acd) A=1, B=1, X=1 (abd) Source: The Art of Software Testing – Glenford Myers
  • 27. McCabe’s Cyclomatic Complexity • Software metric • Developed by Tom McCabe (circa 1976) • Directly measures the number of linearly independent paths through a program’s source code, taking into account the various decision points • Independent of implementation language Source: Wikipedia
  • 30. How Complex Should Code Be? • <10: Simple module, not much risk • 10-20: More Complex; moderate risk • 20-50: Complex; high risk • >50: Untestable; extremely high risk Source: Carnegie Mellon Software Engineering Institute
  • 31. Complexity Caveats • As code is broken into smaller modules to decrease cyclomatic complexity, structural complexity increases • Some modules may have high complexity but are very easy to comprehend and easy to test • High complexity numbers are only an indicator of something to investigate