Bird
0
0

Find the bug in this regression test code:

medium📝 Debug Q7 of 15
Testing Fundamentals - Testing Types and Levels

Find the bug in this regression test code:

def subtract(x, y):
    return x - y

assert subtract(5, 3) == 2
assert subtract(2, 5) == 3
print("Tests done")
AAssertions syntax is invalid
BFunction subtract is incorrectly defined
CPrint statement should be before assertions
DSecond assertion expects wrong result
Step-by-Step Solution
Solution:
  1. Step 1: Evaluate function outputs

    subtract(2, 5) returns -3, but assertion expects 3.
  2. Step 2: Identify assertion failure

    Second assertion will fail due to wrong expected value.
  3. Final Answer:

    Second assertion expects wrong result -> Option D
  4. Quick Check:

    Expected value mismatch causes assertion failure [OK]
Quick Trick: Check expected values carefully in assertions [OK]
Common Mistakes:
  • Assuming function is wrong
  • Thinking print order matters
  • Misreading assertion syntax

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes