Skip to main content

Claude Prompt to Detect and Stabilize Flaky Tests

Identify, diagnose, and fix flaky tests with repeat-run statistics, root-cause checklists, deterministic fixes, and a CI quarantine strategy.

Vul de plaatshouders in

Edit the values, then copy your finished prompt.

Jouw Prompt
prompt.txt

                                

What this prompt does

This prompt helps you fix flaky tests in a [language]/[framework] project using [test_framework]. Given [flaky_count] intermittently failing tests, the AI produces a script to run the suite [repeat_count] times and collect flakiness statistics, a root-cause checklist for [language] (timing, shared state, DB ordering, async races), deterministic before/after fixes per pattern, a test-isolation audit for shared state, a quarantine strategy to unblock CI, retry configuration that separates flaky from real failures, and a monitoring query to track flakiness over time. You feed it the actual [test_names].

The structure works because it treats flakiness as a diagnosis problem, not a retry problem. The repeat-run script gathers evidence, the root-cause checklist narrows the cause, and the fixes target the real source — usually shared state, timing, or DB ordering. Quarantine keeps CI green while you work, and the retry config prevents masking genuine failures. Providing real [test_names] makes every fix concrete.

When to use it

  • Intermittent failures are eroding the team's trust in CI.
  • You need to measure flakiness with repeat runs, not guesswork.
  • You suspect shared state, timing, or DB ordering but need to confirm which.
  • You want a quarantine strategy to unblock CI while fixing.
  • You need retry config that distinguishes flaky from real failures.
  • You want to track flakiness rate over time with a dashboard query.

Example output

You get a script that runs the suite [repeat_count] times and reports flakiness stats, a [language]-specific root-cause checklist, before/after fixes for the patterns behind your [test_names], a shared-state isolation audit, a quarantine plan, retry configuration, and a monitoring query for tracking the flakiness rate.

Pro tips

  • Provide the exact [test_names] and, if possible, their stack traces so fixes target real causes.
  • Run the repeat script enough times — a low [repeat_count] may not reproduce rare flakes.
  • Work through the root-cause checklist before applying fixes; the wrong fix just moves the flake.
  • Use quarantine sparingly and temporarily — it unblocks CI but is not a fix.
  • Configure retries to flag, not hide, flaky tests so real regressions still surface.
  • Re-run the repeat script after each fix to confirm the flake is actually gone.

Frequently Asked Questions

What usually causes flaky tests?
The most common causes are shared state between tests, timing and async races, and non-deterministic database ordering. The prompt provides a `[language]`-specific checklist covering these so you can narrow down which one is behind each of your `[test_names]` before fixing.
How does the repeat-run script help?
It runs the suite `[repeat_count]` times and collects pass/fail statistics per test. This turns intermittent failures into measurable data, letting you confirm which tests are genuinely flaky and verify a fix actually worked rather than guessing from a single run.
Is quarantining tests a real fix?
No. Quarantine temporarily removes a flaky test from blocking CI so the team stays unblocked while you investigate. It is a stopgap, not a solution — the prompt also provides deterministic fixes, and quarantined tests should be repaired and reinstated promptly.
Will retries hide real bugs?
They can if configured carelessly. The prompt sets up retry configuration that distinguishes flaky failures from real ones, so a consistently failing test still surfaces as a genuine regression rather than being silently retried into a false pass.
Engr Mejba Ahmed

Need this built for real?

Engr Mejba Ahmed

AI Developer · Software Engineer

I'm Mejba — I design and ship production AI systems, automations, and full-stack apps. If you want this turned into a working solution for your team, let's talk.

Meer in Testing & QA Automation Prompts

Engr Mejba Ahmed

Engr Mejba Ahmed

Claude Code Expert · Online

👋

Hey there!

Quick Actions

WhatsApp Instant reply

Chat on WhatsApp

+880 1723 741224 · Instant reply

Popular Questions

Engr Mejba Ahmed is connected
Engr Mejba Ahmed is typing...
Engr Mejba Ahmed avatar

✉ Want me to follow up? Drop your email

Engr Mejba Ahmed avatar

📞 Connect Directly

Choose how you'd like to reach me

WhatsApp

+880 1723 741224

Email

[email protected]

✓ Details sent! I'll get back to you shortly.

Powered by OpenAI

335+

Blog Posts

25

AI Courses

63

Projects

Services & Expertise

Pricing & Process

Learning & Resources

Connect & Support