Bird
0
0

Find the bug in this unit test code:

medium📝 Debug Q7 of 15
Testing Fundamentals - Testing Types and Levels
Find the bug in this unit test code:
import unittest

def divide(a, b):
    return a / b

class TestDivide(unittest.TestCase):
    def test_divide(self):
        self.assertEqual(divide(10, 0), 0)

if __name__ == '__main__':
    unittest.main()
AassertEqual should compare to None instead of 0
BTest method name should start with 'check_'
Cdivide function should return integer, not float
DDivision by zero causes runtime error, test is invalid
Step-by-Step Solution
Solution:
  1. Step 1: Analyze divide function and test

    divide(10, 0) causes a division by zero error at runtime.
  2. Step 2: Identify test problem

    The test expects 0 as result, but division by zero raises an exception, so test will error out.
  3. Final Answer:

    Division by zero causes runtime error, test is invalid -> Option D
  4. Quick Check:

    Division by zero causes error [OK]
Quick Trick: Division by zero causes error, not zero result [OK]
Common Mistakes:
  • Expecting zero instead of error on division by zero
  • Ignoring runtime exceptions in tests
  • Wrong test method naming assumptions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes