Functional testing checks whether software produces the expected output for a given input. A test follows a simple recipe: prepare inputs, identify the expected output, obtain the actual output, and compare the two. Because this structure describes how code should behave, a good test can also serve as practical documentation. section 5.1.2
Apply the recipe at different scales:
- For a function, give calculate_mean the list [1, 2, 3, 4] and expect 2.5. section 5.1.2
- For an application workflow, add product 53-DE-232 to a cart and expect the product to appear there. section 5.1.2
- Use unit and integration tests liberally, while treating long, brittle, or manual tests more conservatively. section 5.2.6
Testing a product transformation
With Python's unittest, create Product('shoes', 'S', 'black'), set the expected value to 'SHOES', call transform_name_for_sku(), and compare the result with assertEqual(expected_value, actual_value). A failing assertion reports the differing values, helping locate the defect. Extend the same pattern to color transformation, SKU generation, cart state, and edge cases such as removing more products than the cart contains. section 5.4.3 section 5.4.6
Use the flow diagram to scan the relationship between inputs, expected output, actual output, and comparison. section 5.1.2

