Bird
Raised Fist0

Identify the error in this test suite code snippet:

medium📝 Debug Q6 of Q15
Testing Fundamentals - Test Documentation
Identify the error in this test suite code snippet:
import unittest

class TestCalc(unittest.TestCase):
    def test_subtract(self):
        self.assertEqual(5 - 3, 2)

suite = unittest.TestSuite()
suite.addTest(TestCalc.test_subtract)
runner = unittest.TextTestRunner()
runner.run(suite)
ATextTestRunner cannot run suites
BaddTest expects a test instance, not a method reference
CassertEqual is used incorrectly
DTestCalc class is missing a constructor
Step-by-Step Solution
Solution:
  1. Step 1: Check how addTest is called

    addTest requires a test instance like TestCalc('test_subtract'), not a method reference.
  2. Step 2: Verify other parts

    TestCalc class and assertEqual usage are correct; TextTestRunner runs suites fine.
  3. Final Answer:

    addTest expects a test instance, not a method reference -> Option B
  4. Quick Check:

    addTest needs instance, not method [OK]
Quick Trick: Use test instances, not methods, when adding tests [OK]
Common Mistakes:
MISTAKES
  • Passing method instead of instance to addTest
  • Thinking class needs constructor for tests
  • Misunderstanding assertEqual usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes