You are previewing Refactoring: Improving the Design of Existing Code.

Refactoring: Improving the Design of Existing Code

Cover of Refactoring: Improving the Design of Existing Code by Don Roberts... Published by Addison-Wesley Professional
O'Reilly logo

Chapter 4. Building Tests

If you want to refactor, the essential precondition is having solid tests. Even if you are fortunate enough to have a tool that can automate the refactorings, you still need tests. It will be a long time before all possible refactorings can be automated in a refactoring tool.

I don’t see this as a disadvantage. I’ve found that writing good tests greatly speeds my programming, even if I’m not refactoring. This was a surprise for me, and it is counterintuitive for many programmers, so it’s worth explaining why.

The Value of Self-testing Code

If you look at how most programmers spend their time, you’ll find that writing code actually is quite a small fraction. Some time is spent figuring out what ought to be going on, some ...

The best content for your career. Discover unlimited learning on demand for around $1/day.