From "Refactoring"
🎧 Listen to Summary
Free 10-min PreviewThe Transformative Impact of Automated Self-Testing
Key Insight
Writing tests is often counterintuitive for programmers, yet it significantly increases effectiveness. A major part of programming time is spent debugging, with engineers often experiencing hours or even days trying to locate a single bug, while fixing it is typically quick. Self-testing code, however, drastically reduces this debugging burden by automatically verifying code behavior.
The shift to self-testing began with the concept that 'classes should contain their own tests'. Initially, tests involved manual console output checks, which were tedious. Automating this process by embedding expected outputs directly into the test code and having the computer perform comparisons allows tests to simply report 'OK' if all is well. This automation made running tests as easy as compiling code.
Running automated tests frequently, ideally every time code is compiled or every few minutes for active development, transforms productivity. Bugs introduced are immediately caught by existing tests, pinpointing the issue to the small amount of code just written. This drastically reduces bug-finding time from hours to mere minutes. A robust suite of tests is thus a powerful bug detector, essential for proper refactoring, as it spots inevitable mistakes even when using automated refactoring tools.
📚 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.