0
0
Testing Fundamentalstesting~10 mins

Test suite organization in Testing Fundamentals - Test Execution Trace

Choose your learning style9 modes available
Test Overview

This test checks that multiple related tests are grouped correctly in a test suite and that all tests run and pass as expected.

Test Code - unittest
Testing Fundamentals
import unittest

class CalculatorTests(unittest.TestCase):
    def test_addition(self):
        self.assertEqual(2 + 3, 5)

    def test_subtraction(self):
        self.assertEqual(5 - 2, 3)

class StringTests(unittest.TestCase):
    def test_uppercase(self):
        self.assertEqual('hello'.upper(), 'HELLO')

    def test_isdigit(self):
        self.assertTrue('12345'.isdigit())

if __name__ == '__main__':
    suite = unittest.TestSuite()
    suite.addTest(unittest.makeSuite(CalculatorTests))
    suite.addTest(unittest.makeSuite(StringTests))
    runner = unittest.TextTestRunner()
    runner.run(suite)
Execution Trace - 7 Steps
StepActionSystem StateAssertionResult
1Test suite created and CalculatorTests addedTest suite contains tests: test_addition, test_subtraction-PASS
2StringTests added to test suiteTest suite contains tests: test_addition, test_subtraction, test_uppercase, test_isdigit-PASS
3Test runner starts running test_additionRunning test_addition: 2 + 3 == 5assertEqual(5, 5)PASS
4Test runner runs test_subtractionRunning test_subtraction: 5 - 2 == 3assertEqual(3, 3)PASS
5Test runner runs test_uppercaseRunning test_uppercase: 'hello'.upper() == 'HELLO'assertEqual('HELLO', 'HELLO')PASS
6Test runner runs test_isdigitRunning test_isdigit: '12345'.isdigit() is TrueassertTrue(True)PASS
7All tests completedTest suite run complete with 4 tests, 0 failures-PASS
Failure Scenario
Failing Condition: A test assertion fails, for example test_addition returns wrong result
Execution Trace Quiz - 3 Questions
Test your understanding
What does the test suite do before running tests?
AGroups related tests together to run them all at once
BRuns tests one by one without grouping
COnly runs tests that pass previously
DSkips tests that are slow
Key Result
Organizing tests into suites helps run and manage related tests together, making testing more efficient and structured.