Lesson 15 · Senior testing practice
Flaky tests, determinism, and failure triage
How to reason about -count=3, shared state, ordering, timing, and why a test that passes once may still be lying to you.
Your win: explain why flakiness is a design signal, how to triage repeated-run failures, and what kinds of hidden coupling usually cause them.
Why this topic matters
A flaky test is rarely just an annoying test. That is the key shift. In a weak testing culture, people treat flakiness like weather: unfortunate, but normal. In a stronger testing culture, flakiness is evidence.
It is evidence that a test or the code under test is depending on something unstable, shared, or hidden. That is why the strongest earlier lessons in this course kept pushing independence, fresh setup, and parallel safety. They were already teaching the anti-flake mindset before naming it directly.
Why -count=3 exists
The course already taught you that this repo reruns suites three times to flush out non-determinism. The senior step is understanding what kinds of mistakes that rule is trying to expose.
A test that passes once may still be broken if it depends on leftover state, hidden ordering, timing luck, or reused mutable collaborators. Repetition is what stops “green by accident” from looking trustworthy.
The usual failure families
If you need to triage a flaky test quickly, the search space is smaller than it first feels. Most flakes cluster into a few repeat families:
- Shared mutable state between subtests
- Order dependence between cases or packages
- Time dependence and missing deadlines or fake clocks
- Leaked mocks or contexts reused across cases
- Implicit randomness not controlled by the test
This is why rerun failures are so useful. They narrow the story from “anything could be wrong” to “some hidden dependency is escaping the unit boundary.”
Revisit the workflow rule
Read the workflow and style rules again, this time as anti-flake design decisions rather than formatting rules.
→ .claude/rules/go-test-style.md
→ docs/testing/lessons/0012-running-coverage-workflow.html
Check yourself (from memory)
Q1. What is the best senior interpretation of a flaky test?
-count=3 matter in this repo?Sources. Workflow lesson; house rules.