# How to diagnose a flaky test

> Investigate a test that passes on retry. Compare both attempts, isolate shared state and test order, and give any quarantine an owner and expiry.

Source: https://cueapril.com/knowledge/how-to/diagnose-a-flaky-test
Updated: 2026-12-02
Index: https://cueapril.com/llms.txt

## How do you investigate a test that passes on retry?

Keep the original failure and compare it with the passing attempt on the same build. Isolate likely sources of variation, including clocks, test order, shared data and the product itself. Give any temporary quarantine an owner and expiry.

## Separate the changing conditions

A green retry tells you the outcome varied. It does not establish where the variation came from.

1. Capture the first failure, build, seed, test order and environment. Check whether the intended assertion ran on both attempts.
2. Vary one condition at a time. Compare running alone and in the original order, use isolated records, and control the relevant clock or event.
3. Fix the cause and repeat the conditions that exposed it. If the test is quarantined, record the gap, owner and review date while the fix is pending.

## Worked example: A reminder exists only sometimes

A reminder test passes alone but fails after a test that removes all scheduled reminders. Repeating the tests in that order recreates the failure. Give each test its own schedule, then run the pair in both orders. If the race also occurs with isolated data, investigate whether users can encounter it.

## Try it on your pull request

Choose a change in your repository and tell Cue April what should happen. Review the proposed checks before they run.

[Try Cue April on your repository](https://app.cueapril.com/sign-up/?next=%2Fquality-start)

## Related reading

- [Test quarantine](https://cueapril.com/knowledge/definitions/test-quarantine)

- [Hermetic test](https://cueapril.com/knowledge/definitions/hermetic-test)

- [Run the checks and investigate surprises](https://cueapril.com/knowledge/playbook/run-and-investigate)

[Browse the Knowledge base](https://cueapril.com/knowledge)
