0% found this document useful (0 votes)
12 views4 pages

Testing and Debugging

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views4 pages

Testing and Debugging

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Name : Nathan Joseph Savio Pereira Course name: Software Engineering

Course code:CSE3005 Register no:22BCE11187 Submitted to :Dr.Saravannan

Testing and Debugging Practice

Objective:
To understand the importance of software testing by identifying
bugs, writing test cases, and fixing errors in a small program. This
activity will enhance debugging and test-writing skills.

Activity Steps:
1. Setup:
 Provide or create a small, buggy program (Python or Java).
Example: A Calculator program with intentional errors such as:
o Incorrect mathematical operations.
o Missing or improperly handled edge cases (e.g., division
by zero).
o Syntax errors or logic errors.
Example Program: Buggy Python Calculator
python
Copy code
def add(a, b):
return a - b # Intentional bug

def divide(a, b):


return a / b # No handling for division by zero
def calculator():
print("1. Add")
print("2. Divide")
choice = input("Enter choice: ")
a = int(input("Enter first number: "))
b = int(input("Enter second number: "))
if choice == "1":
print("Result:", add(a, b))
elif choice == "2":
print("Result:", divide(a, b))
else:
print("Invalid choice")

calculator()
2. Assign Tasks:
Task 1: Identify Bugs
 Run the program with test inputs to uncover issues.
 Document the bugs (e.g., incorrect addition, missing error
handling).
Task 2: Write Test Cases
 Write a set of test cases for each function in the program using
a testing framework (e.g., unittest in Python or JUnit in Java).
Example Python Test Cases:
Python
import unittest
from calculator import add, divide

class TestCalculator(unittest.TestCase):
def test_add(self):
self.assertEqual(add(3, 2), 5) # This will fail due to the bug

def test_divide(self):
self.assertEqual(divide(6, 2), 3)

def test_divide_by_zero(self):
with self.assertRaises(ZeroDivisionError):
divide(6, 0)

if __name__ == '__main__':
unittest.main()
Task 3: Fix Errors
 Correct the identified bugs in the program:
o Fix the addition function: return a + b
o Add error handling for division by zero.
o Refactor the program for better readability.
Task 4: Validate with Tests
 Rerun the test cases to ensure all bugs are fixed and edge cases
are handled properly.
Outcome:
By completing this activity, participants will:
 Gain practical experience in identifying and fixing software
bugs.
 Learn how to write and automate test cases.
 Understand the importance of thorough testing and debugging
in software development.

You might also like