Example result: Fix a flaky test that passes and fails at random
AI-generated example · Debug · Flaky Test
Prompt at a glance
Category
Text & chat
Works with
Claude · ChatGPT · Gemini
Length
85 words
Fields to fill
HOW OFTEN, PASTE THE TEST, PASTE, PASTE A FAILING RUN
Last updated

Fix a flaky test that passes and fails at random

A flaky test passes and fails with no code change. This prompt looks for the usual causes, such as async timing, shared state and dates, and rewrites the test so it is reliable without adding sleeps or retries.

text-code-flaky-test-fix — claude — 85 words

Act as a test reliability expert. This test fails about [HOW OFTEN, e.g. 1 in 5 runs] with no code change.

Test code:
[PASTE THE TEST]

Code under test:
[PASTE]

Failure output:
[PASTE A FAILING RUN]

Find the source of the flakiness: timing and async waits, shared state between tests, test order, random data, dates and timezones, network calls or leftover files. Explain the cause in plain words, then rewrite the test so it is deterministic. Do not fix it by adding sleeps or retries.

If you can, run the test 20 times in a loop and paste two different failures. Patterns between them point to the cause.

How to use this prompt

From copy to answer in four steps

  1. 1

    Open Claude and start a new chat.

  2. 2

    Paste the prompt.

  3. 3

    Replace each [BRACKETED] field with your real details and paste in your own text where asked.

  4. 4

    Reply with follow-ups such as "make it shorter" or "make it sound more like me".

FAQ

About this prompt

Which AI tools work with this prompt?

It is written for Claude, ChatGPT and Gemini. Paste it into your preferred tool and adjust the wording if the result is off.

What do I need to fill in?

Replace these fields before you send it: HOW OFTEN, PASTE THE TEST, PASTE, PASTE A FAILING RUN. Each field shows an example in the prompt.

Should I paste private information into the prompt?

Only what the task needs. Remove names, contact details and other sensitive data before pasting a resume or document into any AI tool.

Keep exploring

More chat & writing prompts

See all 424 chat & writing prompts →