Introduction
When you write many tests for your code, it can get hard to keep track of them all. Organizing tests into groups helps you find, run, and understand tests more easily.
Imagine a library where books are sorted into sections like fiction, history, and science. Each section holds books on similar topics, making it easy to find what you want. The librarian also arranges books neatly on shelves and labels them clearly.
┌───────────────────────────┐ │ Test Suite │ ├─────────────┬─────────────┤ │ Setup │ Teardown │ ├─────────────┴─────────────┤ │ Test 1 Test 2 Test 3│ └───────────────────────────┘ │ │ ▼ ▼ Folder Structure mirrors code
import unittest class Calculator: def add(self, a, b): return a + b def subtract(self, a, b): return a - b class CalculatorTests(unittest.TestCase): def setUp(self): self.calc = Calculator() def tearDown(self): pass # Clean up if needed def test_add(self): self.assertEqual(self.calc.add(2, 3), 5) def test_subtract(self): self.assertEqual(self.calc.subtract(5, 3), 2) if __name__ == '__main__': unittest.main()