I've worked at three companies now and they all have the same problem. They write a thousand unit tests that mock everything, then integration tests that mock half the things, then e2e tests that barely run because they're flaky. Meanwhile the bugs that make it to prod are always the ones that happen when services actually talk to each other.
Stop writing unit tests for code that just glues other libraries together. That's not a unit. Spend that time on real integration tests with actual databases. Testcontainers makes this trivial now. Spin up postgres, run your queries, see what actually breaks.
# docker-compose.test.yml - literally all you need
services:
postgres:
image: postgres:16
environment:
POSTGRES_DB: testdb
E2E is for critical paths only. Your entire auth flow, checkout, maybe one admin workflow. Not every button click. That's just slow CI.
The e2e stuff that actually matters tends to be small anyway. I've seen teams spend weeks building elaborate cypress suites that test things that never break, while missing entire categories of bugs because they never tested the integration layer properly.
Pick two. Do them well. Don't do all three just because it looks good on a standup slide.
No responses yet.