Bird
Raised Fist0

Given the following test suite code snippet in Python unittest:

medium📝 Predict Output Q13 of Q15
Testing Fundamentals - Test Documentation
Given the following test suite code snippet in Python unittest:
import unittest

class TestA(unittest.TestCase):
    def test_one(self):
        self.assertTrue(True)

class TestB(unittest.TestCase):
    def test_two(self):
        self.assertEqual(1, 1)

suite = unittest.TestSuite()
suite.addTest(TestA('test_one'))
suite.addTest(TestB('test_two'))
runner = unittest.TextTestRunner()
result = runner.run(suite)

What will be the result of running this test suite?
ABoth tests pass and the suite completes successfully
BTestA fails but TestB passes
CTestB fails but TestA passes
DBoth tests fail and the suite reports errors
Step-by-Step Solution
Solution:
  1. Step 1: Analyze each test case

    TestA.test_one asserts True is True, which passes. TestB.test_two asserts 1 equals 1, which also passes.
  2. Step 2: Understand test suite execution

    The suite runs both tests; since both assertions are correct, no failures occur.
  3. Final Answer:

    Both tests pass and the suite completes successfully -> Option A
  4. Quick Check:

    Assertions true = tests pass = D [OK]
Quick Trick: Check each assertion; all true means all tests pass [OK]
Common Mistakes:
MISTAKES
  • Assuming tests fail without checking assertions
  • Confusing test method names
  • Ignoring that both tests run in suite

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Testing Fundamentals Quizzes