A unit test checks behavior at the smallest unit of change. It can define correct behavior before implementation, constrain design, and catch defects before they spread. section 5.2 section 5.9
Use unit tests where quick feedback protects meaningful behavior:
- Test business rules, calculations, transformations, and invariants; these are suited to unit-level checks. section 5.3
- Prefer tests that run quickly, remain stable through refactoring, and define correctness rather than police internal calls. section 5.2
- Choose the test layer by risk: unit tests suit high-impact business calculations, while boundary and customer-journey risks may need other layers. section 5.3
Listing 5.2 A typical TDD test
def test_shipping_cost_for_domestic_package_under_5kg():
assert calculate_shipping(weight=3, destination="domestic") == 5.99A test-first example specifies the expected shipping cost for a domestic package under five kilograms. section 5.2
Treat the test as a control, not a coverage target: protect behavior where early detection prevents rework, and avoid accumulating slow or untrusted checks. section 5.2 section 5.9

















