A few folks at Google have put together a very readable PDF book called Writing Testable Code. It covers four flaws, and explains, in admirable detail and great clarity, why they are a bad thing, and how to fix them. I don’t usually like articles like this—I find them too vague and non-specific—but this is a brilliant exception. The four flaws are:
- Constructor does real work
- Digging into collaborators
- Brittle global state and singletons
- Class does too much
(It’s not just about testable code; it’s about good code in general. Testable code is much easier to reason about than untestable code.)