Lecture 12 1 Testing and Debugging
Lecture 12 1 Testing and Debugging
in Python
Sukrit Gupta
2 Testing
4 Exceptions
1
source: LinkedIn, 1st January, 2022
Sukrit Gupta Intro to Computing and Data Structures 5/31
Ensuring product quality
Often developers who have written the code are biased or are
unaware of the real world scenario in which the code will be used.
They are, therefore, not the best people to judge whether a code
works as expected.
Therefore, in each organization there is a dedicated team of
professionals that test the product.
Testing has been evolved to cater to different types of errors that
creep into software.
Testing
def factorial(n):
fact = 1
while n>1:
fact *= n
n -=1
return fact
Let us say that you perform testing and you find that the program
does not work as intended. What do you do?
You De-bug.
Debugging is the process of trying to fix a program that you
already know does not work as intended.
To make the program easier to test and debug, good programmers
break the program up into separate components that can be
implemented, tested, and debugged independently of other
components.
Assumption is that syntax errors and semantic errors have already
been tackled.
2
www.npr.org
Sukrit Gupta Intro to Computing and Data Structures 20/31
Both covert and intermittent
Exceptions
The try block lets you test a block of code for errors.
The except block lets you handle the error.
If the programmer forgets to include the except block of code and
the exception is raised, the program will halt immediately.
This is good because it creates an overt bug and makes it easy to
debug the program.
1 raise exceptionName(arguments)
2 Testing
4 Exceptions