What I think I know about testing
- Convincing your organization that unit tests are a good investment is a 1999 problem. Everyone tests now, the conversation should be about testing effectively.
- The goal of testing is not to produce a good design. At best, that’s a nice side-effect.
- The goal of testing is not to document the business. At best, that’s a nice side-effect.
- The goal of testing is to catch bugs and prevent regressions.
- Prescribing TDD is like prescribing top-down programming or dark mode. If it works for you, fine; if it doesn’t, fine.
- Not every layer of the code needs to be tested in isolation.
- Hell, not every layer of the code needs to be tested.
- The more tests are not the merrier.
- It’s OK to skip tests on a prototype.
- If it doesn’t have tests, it’s a prototype.
- Coverage metrics can tell you what you missed. Targeting a specific coverage number is silly.
- Integration tests are almost always preferable to unit tests.
- Integration tests should be pushed as close as possible to end-to-end tests—without making them slow, brittle, or hard to set up.
- Mocks are a bad smell.
- The database should not be mocked.
-
Beyond helper functions, trying to remove duplication makes test code worse.
(I’m a proud grug-brained developer.)