Regression testing is performed to ensure that previously developed and tested software still performs correctly after changes or updates have been made. It involves rerunning previously executed tests to verify that no new issues or bugs have been introduced. This technique is crucial in preventing the recurrence of previously resolved bugs.
Example:
# Original code
def calculate_discount(price, discount):
if price >= 100:
return price - discount
else:
return price
# Revised code
def calculate_discount(price, discount):
if price >= 100 and discount > 0:
return price - discount
else:
return price