13 / 57 · 26 Testing Like a Senior · Assertions and Flaky Tests← prev⊞ allnext →☰ Read as one page
3.4Key Takeaways
- Write assertions that diagnose failures, not just detect them — include context in error messages
- Use soft assertions when you need to check multiple conditions in one test
- Build custom assertion helpers that encode domain knowledge
- Flaky tests have root causes: timing, shared state, external dependencies, order dependency, non-deterministic data
- Never use
sleep()as a synchronization strategy — use event-driven waits - Track flaky test rates and treat rising flakiness as an infrastructure problem, not individual test problems