Bird
0
0

Identify the error in the following Python unit test code:

medium📝 Debug Q14 of 15
Testing Fundamentals - Testing Types and Levels
Identify the error in the following Python unit test code:
def divide(a, b):
    return a / b

assert divide(10, 2) == 5
assert divide(5, 0) == 0
AThe function should return integer only
BDivision by zero causes runtime error
CThe first assertion is incorrect
DAssertions are missing parentheses
Step-by-Step Solution
Solution:
  1. Step 1: Analyze function behavior

    Function divides a by b. Dividing by zero is not allowed and causes an error.
  2. Step 2: Check assertions

    First assertion divides 10 by 2, which is valid. Second assertion divides 5 by 0, which causes a runtime ZeroDivisionError.
  3. Final Answer:

    Division by zero causes runtime error -> Option B
  4. Quick Check:

    Divide by zero error in second assert [OK]
Quick Trick: Watch for zero division in tests [OK]
Common Mistakes:
  • Ignoring division by zero error
  • Thinking assertions need parentheses in Python
  • Assuming function returns only integers

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes