Organize and run multiple test cases in a test suite
Preconditions (3)
✅ Expected Result: All three tests run successfully and pass, showing a summary report with 3 passed tests
import pytest # test_math.py def test_addition(): result = 2 + 3 assert result == 5 # test_strings.py def test_uppercase(): text = "hello" assert text.upper() == "HELLO" # test_lists.py def test_append(): items = [1, 2, 3] items.append(4) assert len(items) == 4 # test_suite.py import test_math import test_strings import test_lists if __name__ == "__main__": pytest.main()
The code defines three test functions, each in a separate section simulating separate files: test_math.py, test_strings.py, and test_lists.py. Each test checks a simple operation with an assertion.
The test_suite.py file imports these test modules and runs pytest to discover and execute all tests automatically.
This organization shows how to group related tests and run them together as a suite, following pytest conventions for easy test discovery and reporting.
Now add data-driven testing with 3 different inputs for the addition test
test suite in software testing?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)suite = unittest.TestSuite()
suite.addTest(TestClass('test_one'))
suite.addTest(TestClass('test_two'))
runner.run(suite)test_three is not running?test_one and test_two. test_three is missing.test_three is valid if it starts with 'test'. Runner supports many tests. Class inheritance assumed correct.Pass the test and this pattern moves unknown