SlideShare a Scribd company logo
White Box Testing on a Python Function
By
Gevita Chinnaiah
• You are given a Python function that
calculates the factorial of a number using
recursion.
• Perform White Box Testing to analyze its
control flow, loops, and data flow.
– Identify all execution paths in the function.
– Write test cases to ensure 100% statement
and branch coverage.
– Implement the test cases in Python using
unittest.
Lab Question: White Box Testing on a Python Function
Python Function (To Be Tested)
• Step 1: Identify Execution Paths
– The function has three main paths:
• If n < 0, return "Invalid input".
• If n == 0 or n == 1, return 1.
• If n > 1, recursively compute n * factorial(n - 1).
• We need to create test cases covering all
these paths.
Solution: White Box Testing Approach
• Using Python’s unittest module:
Step 2: Write Test Cases
• Statement Coverage:
– Every line of code is executed at least once.
• Branch Coverage:
– Each condition (if, elif, else) is tested with
different inputs.
• Loop Coverage:
– The recursive function calls itself until n == 1,
ensuring all iterations are tested.
Step 3: Validate Coverage
Expected Output
• Step 1: Introduce an Error in the Code
• What is Wrong?
– Instead of decrementing n (n - 1), the function increments n (n
+ 1).
– This results in infinite recursion, causing a RecursionError
Simulating an Error in the Factorial Function and Fixing It
• Expected Output (with the error)
• E means an error occurred.
• RecursionError shows that the function never stops
calling itself, leading to a crash.
Step 2: Run the Test Cases and Observe the Error
• We correct the recursion step by changing
(n + 1) back to (n - 1):
Step 3: Fix the Error
• Expected Output (after the fix)
Step 4: Re-run the Test Cases
Thank You

More Related Content

PPTX
Module_2_1_Building Python Programs_Final.pptx
PPTX
lab-8 (1).pptx
PPTX
PPTX
Step Count Method for Time Complexity Analysis.pptx
PPTX
Iterative control structures, looping, types of loops, loop working
PPT
11 whiteboxtesting
PPTX
Recursion
PPTX
PYTHON.pptx
Module_2_1_Building Python Programs_Final.pptx
lab-8 (1).pptx
Step Count Method for Time Complexity Analysis.pptx
Iterative control structures, looping, types of loops, loop working
11 whiteboxtesting
Recursion
PYTHON.pptx

Similar to White Box Testing on a Python Function.pptx (20)

PPTX
Algorithm-RepetitionSentinellNestedLoop_Solution.pptx
PDF
Reactive programming
PDF
Repetition, Basic loop structures, Loop programming techniques
PPTX
Formal Methods lecture 01
PDF
Python Programming unit5 (1).pdf
PPTX
Going loopy - Introduction to Loops.pptx
PPTX
Introduction to White box testing
PDF
Cyn meetup
PPTX
Python: Object-Oriented Testing (Unit Testing)
PPT
UNIT-2-PPTS-DAA.ppt
PPT
White boxvsblackbox
PDF
LC2018 - Input Validation in PureScript
PPT
Seii unit6 software-testing-techniques
PDF
Software Engineering : Software testing
PPTX
Java-Programming.forBSITSTUDENTfreespptx
PDF
Start MPC
PPT
New software testing-techniques
PPTX
Recursion
PPT
Dynamic Testing
Algorithm-RepetitionSentinellNestedLoop_Solution.pptx
Reactive programming
Repetition, Basic loop structures, Loop programming techniques
Formal Methods lecture 01
Python Programming unit5 (1).pdf
Going loopy - Introduction to Loops.pptx
Introduction to White box testing
Cyn meetup
Python: Object-Oriented Testing (Unit Testing)
UNIT-2-PPTS-DAA.ppt
White boxvsblackbox
LC2018 - Input Validation in PureScript
Seii unit6 software-testing-techniques
Software Engineering : Software testing
Java-Programming.forBSITSTUDENTfreespptx
Start MPC
New software testing-techniques
Recursion
Dynamic Testing
Ad

More from GevitaChinnaiah (20)

PPTX
Mobile Application and Developments.pptx
PPTX
Building a To-Do List App lecture 1.pptx
PPTX
Software Quality and Testing note 1.pptx
PPTX
Introduction to JavaScript DOM and User Input.pptx
PPT
391Lecture0909 Vision control of git.ppt
PPTX
Introduction to Python and Basic Syntax.pptx
PPTX
Software Programming with Python II.pptx
PPT
a basic java programming and data type.ppt
PPTX
Install an Operating System.pptx
PPTX
Solve Stop Code Memory Management on Windows.pptx
PPTX
windows memory management.pptx
PPTX
Introduction to Database Management.pptx
PPT
OPERATING SYSTEM CHAPTER 3.ppt
PPTX
Lecture 3 React Native with Database.pptx
PPTX
Database Management System (DBMS).pptx
PPTX
Operating System chapter 1.pptx
PPTX
Lecture 2 Styling and Layout in React Native.pptx
PPTX
Lecture 1 Introduction to React Native.pptx
PPTX
Understanding Applications.pptx
PPTX
Operating System 2.pptx
Mobile Application and Developments.pptx
Building a To-Do List App lecture 1.pptx
Software Quality and Testing note 1.pptx
Introduction to JavaScript DOM and User Input.pptx
391Lecture0909 Vision control of git.ppt
Introduction to Python and Basic Syntax.pptx
Software Programming with Python II.pptx
a basic java programming and data type.ppt
Install an Operating System.pptx
Solve Stop Code Memory Management on Windows.pptx
windows memory management.pptx
Introduction to Database Management.pptx
OPERATING SYSTEM CHAPTER 3.ppt
Lecture 3 React Native with Database.pptx
Database Management System (DBMS).pptx
Operating System chapter 1.pptx
Lecture 2 Styling and Layout in React Native.pptx
Lecture 1 Introduction to React Native.pptx
Understanding Applications.pptx
Operating System 2.pptx
Ad

Recently uploaded (20)

PDF
Basic Mud Logging Guide for educational purpose
PDF
Classroom Observation Tools for Teachers
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Insiders guide to clinical Medicine.pdf
PPTX
Week 4 Term 3 Study Techniques revisited.pptx
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
01-Introduction-to-Information-Management.pdf
PPTX
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PDF
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
Cell Structure & Organelles in detailed.
PPTX
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
PPTX
Microbial diseases, their pathogenesis and prophylaxis
Basic Mud Logging Guide for educational purpose
Classroom Observation Tools for Teachers
O5-L3 Freight Transport Ops (International) V1.pdf
Insiders guide to clinical Medicine.pdf
Week 4 Term 3 Study Techniques revisited.pptx
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
102 student loan defaulters named and shamed – Is someone you know on the list?
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
01-Introduction-to-Information-Management.pdf
Introduction_to_Human_Anatomy_and_Physiology_for_B.Pharm.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
BÀI TẬP BỔ TRỢ 4 KỸ NĂNG TIẾNG ANH 9 GLOBAL SUCCESS - CẢ NĂM - BÁM SÁT FORM Đ...
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
Renaissance Architecture: A Journey from Faith to Humanism
Cell Structure & Organelles in detailed.
The Healthy Child – Unit II | Child Health Nursing I | B.Sc Nursing 5th Semester
Microbial diseases, their pathogenesis and prophylaxis

White Box Testing on a Python Function.pptx

  • 1. White Box Testing on a Python Function By Gevita Chinnaiah
  • 2. • You are given a Python function that calculates the factorial of a number using recursion. • Perform White Box Testing to analyze its control flow, loops, and data flow. – Identify all execution paths in the function. – Write test cases to ensure 100% statement and branch coverage. – Implement the test cases in Python using unittest. Lab Question: White Box Testing on a Python Function
  • 3. Python Function (To Be Tested)
  • 4. • Step 1: Identify Execution Paths – The function has three main paths: • If n < 0, return "Invalid input". • If n == 0 or n == 1, return 1. • If n > 1, recursively compute n * factorial(n - 1). • We need to create test cases covering all these paths. Solution: White Box Testing Approach
  • 5. • Using Python’s unittest module: Step 2: Write Test Cases
  • 6. • Statement Coverage: – Every line of code is executed at least once. • Branch Coverage: – Each condition (if, elif, else) is tested with different inputs. • Loop Coverage: – The recursive function calls itself until n == 1, ensuring all iterations are tested. Step 3: Validate Coverage
  • 8. • Step 1: Introduce an Error in the Code • What is Wrong? – Instead of decrementing n (n - 1), the function increments n (n + 1). – This results in infinite recursion, causing a RecursionError Simulating an Error in the Factorial Function and Fixing It
  • 9. • Expected Output (with the error) • E means an error occurred. • RecursionError shows that the function never stops calling itself, leading to a crash. Step 2: Run the Test Cases and Observe the Error
  • 10. • We correct the recursion step by changing (n + 1) back to (n - 1): Step 3: Fix the Error
  • 11. • Expected Output (after the fix) Step 4: Re-run the Test Cases