Bird
0
0

Given this test suite code snippet, what will be the output when running the suite?

medium📝 Predict Output Q4 of 15
Testing Fundamentals - Test Documentation
Given this test suite code snippet, what will be the output when running the suite?
import unittest

class TestMath(unittest.TestCase):
    def test_add(self):
        self.assertEqual(2 + 2, 4)

class TestString(unittest.TestCase):
    def test_upper(self):
        self.assertEqual('abc'.upper(), 'ABC')

suite = unittest.TestSuite()
suite.addTest(TestMath('test_add'))
suite.addTest(TestString('test_upper'))

runner = unittest.TextTestRunner()
result = runner.run(suite)
ABoth tests pass, output shows 2 tests run with OK
BBoth tests fail, output shows errors
COnly test_add runs, test_upper is skipped
DSyntax error stops the tests from running
Step-by-Step Solution
Solution:
  1. Step 1: Analyze test methods

    Both test_add and test_upper have correct assertions that should pass.
  2. Step 2: Check test suite setup

    Both tests are added to suite and run by TextTestRunner.
  3. Final Answer:

    Both tests pass, output shows 2 tests run with OK -> Option A
  4. Quick Check:

    Correct tests added and pass = 2 tests OK [OK]
Quick Trick: All added tests run unless skipped or error [OK]
Common Mistakes:
  • Assuming tests fail without checking assertions
  • Thinking tests are skipped without skip decorators
  • Confusing syntax errors with runtime

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes