flaky-tests-pro
Skill8 starsChanged 12 days agoMITView on GitHub
Investigates, fixes, and prevents flaky tests in Apple and Android projects — reproducing a flake on demand (xcodebuild test repetitions, swift test --repeat-until, Gradle and instrumentation loops), classifying the cause (async waits, shared state, order dependence, time, randomness, network, devices), fixing it at the source in Swift Testing, XCTest, XCUITest, JUnit, coroutines, Compose, and Espresso, and setting a CI policy for retries, quarantine, and flake tracking. Use when a test passes and fails without a code change, CI is red intermittently, someone proposes a retry or a skip, or when auditing a suite for flake risk.
In this repository40 other files it gives its agents.
- AGENTS.mdAGENTS.md
- docs/agents.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- android-accessibility-proSkill
- android-adaptive-layout-proSkill
- android-compose-proSkill
- android-coroutines-proSkill
- android-design-system-proSkill
- android-gradle-architecture-proSkill
- android-library-proSkill
- android-memory-storage-proSkill
- android-modularization-proSkill
- app-intents-proSkill
- beta-deployment-proSkill
- coredata-swift6-proSkill
- cross-platform-parity-proSkill
- foundation-models-proSkill
- instruments-profiling-proSkill
- linting-proSkill
- localization-proSkill
- motion-design-proSkill
- r8-shrink-proSkill
- store-compliance-proSkill
- swift-accessibility-proSkill
- swift-adaptive-layout-proSkill
- swift-concurrency-proSkill
- swiftdata-proSkill
- swift-design-system-proSkill
- swift-docc-proSkill
- swift-error-handling-proSkill
- swift-library-proSkill
- swift-logging-proSkill
- swift-memory-storage-proSkill
- swift-modularization-proSkill
- swift-package-proSkill
- swift-testing-proSkill
- swiftui-proSkill
- visionos-proSkill
- xcode-security-proSkill
- xml-to-compose-migration-proSkill
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 35
Never "fix" a flake by raising a timeout, adding a sleep, adding a retry, or deleting the assertion.
- Very specific: line 41
No shared mutable state between tests: No statics or singletons left dirty, no UserDefaults.standard / real SharedPreferences, no fixed …
- Distinctive: line 42
Order-independent: Every test passes alone, first, last, and in parallel.
- Distinctive: line 44
Deterministic assertions: No reliance on dictionary or set ordering, hash values, floating-point equality without a tolerance, or the …
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
A flaky test passes and fails on the same code. It is a bug, either in the test or in the code under test, and a retry only hides it. This skill is the deep companion to the always-on apple-testing-strategy.md and android-testing-strategy.md rules. Report only genuine problems.
Pick the mode from the request:
- Fix: a named test flakes. Reproduce, classify, fix, verify (below).
- Triage a suite: CI is intermittently red and nobody knows which tests. Find the flaky set from CI history or repetition runs, rank by failure rate and cost, then fix the top ones.
- Prevent: review tests or a PR for flake risk with the checklist below.
- Set policy: decide how CI retries, quarantines, and tracks flakes, from
references/ci-policy.md.
Load only what the task needs:
references/causes-and-fixes.md— the cause taxonomy, the signal each cause leaves, and the fix in Swift and Kotlin. Load for every Fix and Prevent task.references/apple.md— reproducing withxcodebuildrepetition flags, test plans, andswift test; reading.xcresult; Swift Testing, XCTest, and XCUITest fixes; known-issue and disabling APIs.references/android.md— repeating JVM and instrumented tests, the test-retry plugin, Test Orchestrator, Gradle Managed Devices, Compose and Espresso synchronization, Robolectric loopers,@FlakyTest.references/ci-policy.md— retry and quarantine policy, flake tracking, and the external tools and agent skills worth knowing (Tuist, Develocity, Marathon, Firebase Test Lab, and others).
Fix Workflow
- Reproduce before touching code. Run the one test many times, in the same conditions CI uses (parallel on, same device or simulator, same order). Record the failure rate, such as 3 of 200. A flake you can't reproduce, you can't prove fixed. If it won't fail alone, run it with its whole suite or with randomized order: the cause is probably shared state or order.
- Read the failures, not just the count. Collect the failure messages and stack traces from several failing runs. Different messages across runs usually mean a race; the same message usually means one bad wait or assumption.
- Classify the cause with
references/causes-and-fixes.md. Name it in the report ("async wait: asserts before the load finishes"). - Fix the source. Inject the clock, await the real signal, isolate the state, stub the network. Fix the code under test when the race is real there: a flaky test that exposes a production race is the test working.
- Verify with the same repetition that reproduced it, at least 10 times the original failure interval (a 1-in-50 flake needs 500 clean runs). Then run the full suite once to make sure the fix didn't move the problem.
- Remove any retry, skip, or known-issue marker the flake was carrying, in the same change.
Never "fix" a flake by raising a timeout, adding a sleep, adding a retry, or deleting the assertion. Raising a timeout is acceptable only when the operation is genuinely slow and bounded, and the report says so.
Prevention Checklist
- No sleeps. No
sleep,Thread.sleep,Task.sleep,usleep,SystemClock.sleep, ordelayused to wait for real work. Await a completion, a confirmation, a predicate, or virtual time. - Controlled time and randomness. Clocks,
Date()/System.currentTimeMillis(), UUIDs, random seeds, and time zones are injected or fixed. - No shared mutable state between tests. No statics or singletons left dirty, no
UserDefaults.standard/ realSharedPreferences, no fixed file paths, no shared database file. Each test builds its own fixtures. - Order-independent. Every test passes alone, first, last, and in parallel.
- No live network or real services. Stub at the protocol or transport layer (
URLProtocol,MockWebServer, fakes). - Deterministic assertions. No reliance on dictionary or set ordering, hash values, floating-point equality without a tolerance, or the device's locale.
- UI tests wait on state, never on time, find elements by identifier or test tag, start from a known app state (launch arguments, cleared data), and run with animations off.
- Bounded tests. A hung test fails fast with a time limit instead of stalling the whole run.
- Retries in CI are reported, not silent, and every quarantined test has an owner and an issue.
Output Format
For a fix: the test, the reproduction command and failure rate before, the cause category with the evidence, the change (before/after code), and the verification command and clean-run count after.
For a review or triage: group findings by severity: flaky now (a reproduced or CI-observed flake), flake risk (a checklist violation that will flake under load, parallelism, or another device), policy (silent retries, quarantine without owners, no tracking). Give each as file:line, the cause category, and the fix. End with the count per severity and the first three fixes.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

