finds.dev← search

// the find

mhevery/guide-to-testable-code

★ 225 · updated Mar 2024

This is the classic Google testability guide, originally written by Miško Hevery (creator of AngularJS) and collaborators, laying out four recurring code smells that make unit testing hard: constructors doing real work, digging into collaborators, global state/singletons, and classes doing too much. It's for developers who want a sharp, opinionated checklist to point to in code review rather than a library or tool.

The four-flaw framework is still the clearest practical explanation of why certain code resists testing — each comes with concrete warning signs (e.g. 'new in a constructor', 'method chains with more than one dot') rather than vague principles. It's split into short, linkable documents per flaw, which makes it easy to drop a specific link into a PR comment instead of a wall of text. It's genuinely battle-tested advice distilled from reviewing a huge amount of code at Google, not someone's personal opinion blog post.

The README itself has no content beyond links — you have to click into four separate markdown files to get the actual guidance, which is a clunky reading experience. Some of the advice shows its age: the hostility toward static methods and singletons is less relevant in ecosystems with strong mocking support (Python's unittest.mock, Kotlin's mockk, etc.) where those patterns are easily testable anyway. There's no code in any language — it's prose and warning signs only, so you can't lint for this automatically or point a tool at it. It's a frozen reference (last real update years ago) with no active maintenance, so don't expect it to evolve with modern testing practices.

View on GitHub →

// want more like this?

We dig through GitHub every week and send a few repos picked for what you actually care about — each with an honest take like this one.

Get finds in your inbox → Search again →