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.
This test checks that multiple related tests are grouped correctly in a test suite and that all tests run and pass as expected.
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)
| Step | Action | System State | Assertion | Result |
|---|---|---|---|---|
| 1 | Test suite created and CalculatorTests added | Test suite contains tests: test_addition, test_subtraction | - | PASS |
| 2 | StringTests added to test suite | Test suite contains tests: test_addition, test_subtraction, test_uppercase, test_isdigit | - | PASS |
| 3 | Test runner starts running test_addition | Running test_addition: 2 + 3 == 5 | assertEqual(5, 5) | PASS |
| 4 | Test runner runs test_subtraction | Running test_subtraction: 5 - 2 == 3 | assertEqual(3, 3) | PASS |
| 5 | Test runner runs test_uppercase | Running test_uppercase: 'hello'.upper() == 'HELLO' | assertEqual('HELLO', 'HELLO') | PASS |
| 6 | Test runner runs test_isdigit | Running test_isdigit: '12345'.isdigit() is True | assertTrue(True) | PASS |
| 7 | All tests completed | Test suite run complete with 4 tests, 0 failures | - | PASS |