I still write tests
Douglas Pereira
Not a cathedral of mocks. Not 90% coverage as a religion. A few tests that fail when the thing I care about breaks.
Pyramid, trophy, whatever — pick the expensive bugs
Fowler's test pyramid still explains cost: many fast unit tests, fewer integrated, few e2e. Kent C. Dodds' testing trophy shifts weight to integration with Testing Library because the user does not click a mock.
I write the test I want at 11pm: given this input, the user sees this, we do not charge twice, the other tenant is not in the JSON.
test('does not charge twice on retry', async () => {
await charge(invoice)
await charge(invoice)
expect(await payments.count(invoice.id)).toBe(1)
})
The agent will happily assert that a mock returned a mock. That test is a compliment to the mock. Don't mock what you don't own still applies.
Determinism or delete it
Time, network, randomness: inject them. Flakes train the team to ignore red. If the suite is slow, I delete tests, I do not delete the suite. A mean little suite beats a museum.
Property tests (fast-check, Hypothesis) when the invariant is algebraic (parse/print, order independence). One property can replace a handful of examples — not the other way around.
References
- Martin Fowler, The Practical Test Pyramid
- Kent C. Dodds, The Testing Trophy
- Testing Library: Guiding Principles
- Google Testing Blog: Don't mock types you don't own
- Kent Beck, Test-Driven Development: By Example
- fast-check