Cover of Refactoring by Martin Fowler, Kent Beck - Business and Economics Book

From "Refactoring"

Author: Martin Fowler, Kent Beck
Publisher: Addison-Wesley Professional
Year: 1999
Category: Computers

🎧 Free Preview Complete

You've listened to your free 10-minute preview.
Sign up free to continue listening to the full summary.

🎧 Listen to Summary

Free 10-min Preview
0:00
Speed:
10:00 free remaining
Chapter 4: Building Tests
Key Insight 3 from this chapter

Strategic Approaches to Comprehensive Test Design

Key Insight

Test design should be risk-driven, prioritizing complex code areas and potential failure points over exhaustively testing every public method, especially simple accessors. The goal is to maximize bug detection for the effort expended, acknowledging that even incomplete testing provides substantial benefits. Concentrating on high-risk areas ensures the most value from testing, as trying to write too many tests can lead to discouragement and insufficient overall test coverage.

Beyond 'happy path' scenarios, a comprehensive test suite rigorously probes boundary conditions. This includes testing with empty collections (e.g., zero producers), zero values (e.g., 'demand = 0'), negative values (e.g., 'demand = -1'), and invalid inputs such as empty strings (e.g., 'demand = ""'). Such tests uncover how the system behaves under edge cases, often leading to important design questions about domain constraints, error handling, or input validation. For example, testing with 'producers: ""' might expose an unexpected 'TypeError' during object construction, prompting a reevaluation of input validation needs depending on the data source's trustworthiness.

Testing is an iterative activity, requiring continuous refinement of the test suite as much as the production code. A crucial practice when a bug is reported is to first write a new unit test that reliably exposes the bug before attempting to fix it. This ensures the bug is definitively resolved and prevents future regressions. While measuring 'enough' testing is subjective, confidence that new defects would cause a test to fail, allowing for confident refactoring and a 'green bar' state, is the ultimate goal. Over-testing, characterized by spending more time modifying tests than the code itself, is rare compared to the prevalent issue of under-testing.

📚 Continue Your Learning Journey — No Payment Required

Access the complete Refactoring summary with audio narration, key takeaways, and actionable insights from Martin Fowler, Kent Beck.