Skip to content
Skillpedia
Testing5.9k Β· #14544

fix-flaky-tests

What it does

This skill investigates flaky automated tests, which pass and fail without a code change, and fixes them. It is for developers who want their test suite to be reliable.

When to use it

  • βœ“When a test is marked as flaky in Tuist and you want it fixed.
  • βœ“When many tests fail randomly and you want to find the common cause.
  • βœ“When you want to discover and fix all flaky tests in a project.

Skill link

https://github.com/tuist/tuist/blob/main/skills/skills/fix-flaky-tests/SKILL.md

Copy it and paste it into your AI (Claude, ChatGPT or Cursor), asking it to follow the instructions.

How to use

The easiest way: copy the message and paste it into your AI. It reads the skill and follows the instructions.

Ready-to-paste message

Use this skill to help me: https://github.com/tuist/tuist/blob/main/skills/skills/fix-flaky-tests/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
Want your AI to find skills like this on its own?Install the free Skillpedia MCP: one line, and it searches 15,000+ skills before each task.Install in 1 minute β†’

Example of what to ask your AI

β€œFind the flaky tests in my project and fix the one that fails most often.”

5 new skills a week. 1 minute to read.

How it works

The agent reads each flaky test's reliability and failure details, reads its source at the reported line, identifies the pattern causing flakiness, fixes it, then runs the test several times to confirm.

Technical content (original SKILL.md)

Original text by the author, straight from GitHub.

Fix Flaky Tests

Quick Start

You'll typically receive a Tuist test case URL or identifier. Follow these steps to investigate and fix it:

  1. Run tuist test case show <id-or-identifier> --json to get reliability metrics for the test.
  2. Run tuist test case run list Module/Suite/TestCase --flaky --json to see flaky run patterns.
  3. Run tuist test case run show <test-case-run-id> --json on failing flaky runs to get failure messages and file paths.
  4. Read the test source at the reported path and line, identify the flaky pattern, and fix it.
  5. Verify by running the test multiple times to confirm it passes consistently.

If no specific test is provided, start with the Discovery section below.

Discovery

When no specific test case is provided, find all flaky tests in the project:

tuist test case list --flaky --json --page-size 50

This returns all test cases currently flagged as flaky. Key fields:

  • module.name / suite.name / name β€” the test identifier
  • avg_duration β€” helps prioritize (fix fast unit tests first)
  • is_quarantined β€” whether the test is already quarantined

Triage strategy:

  1. Group tests by suite β€” multiple flaky tests in the same suite often share a root cause.
  2. Check if failures share a test_run_id β€” tests that all failed in the same run may have been killed by a process crash, not individual test bugs.
  3. Look at failure messages to categorize: test logic bugs vs infrastructure issues (network errors, server 502s, conflicts on retry).

Investigation

1. Get test case metrics

You can pass either the UUID or the Module/Suite/TestCase identifier:

tuist test case show <id> --json
tuist test case show Module/Suite/TestCase --json

Key fields:

  • reliability_rate β€” percentage of successful runs (higher is better)
  • flakiness_rate β€” percentage of runs marked flaky in the last 30 days
  • total_runs / failed_runs β€” volume context
  • last_status β€” current state

2. View flaky run history

tuist test case run list Module/Suite/TestCase --flaky --json

The identifier uses the format ModuleName/SuiteName/TestCaseName or ModuleName/TestCaseName when there is no suite. This returns only runs that were detected as flaky.

3. View full run history

tuist test case run list Module/Suite/TestCase --json --page-size 20

Look for patterns:

  • Does it fail on specific branches?
  • Does it fail only on CI (is_ci: true) or also locally?
  • Are failures clustered around specific commits?

4. Get failure details

tuist test case run show <test-case-run-id> --json

Key fields:

  • failures[].message β€” the assertion or error message
  • failures[].path β€” source file path
  • failures[].line_number β€” exact line of failure
  • failures[].issue_type β€” type of issue (assertion_failure, etc.)
  • repetitions β€” if present, shows retry behavior (pass/fail sequence)
  • test_run_id β€” the broader test run this execution belongs to
  • crash_report β€” crash report data (present when the test runner crashed); contains exception_type, signal, exception_subtype, and triggered_thread_frames

Code Analysis

  1. Open the file at failures[0].path and go to failures[0].line_number.
  2. Read the full test function and its setup/teardown.
  3. Identify which of the common flaky patterns below applies.
  4. Check if the test shares state with other tests in the same suite.

Common Flaky Patterns

Timing and async issues

  • Missing waits: Test checks a result before an async operation completes. Fix: use await, expectations with timeouts, or polling.
  • Race conditions: Multiple concurrent operations access shared state. Fix: synchronize access or use serial queues.
  • Hardcoded timeouts: sleep(1) or fixed delays that are too short on CI. Fix: use condition-based waits instead of fixed delays.

Shared state

  • Test pollution: One test modifies global/static state that another test depends on. Fix: reset state in setUp/tearDown or use unique instances per test.
  • Singleton contamination: Shared singletons carry state between tests. Fix: inject dependencies or reset singletons.
  • File system leftovers: Tests leave files that affect subsequent runs. Fix: use temporary directories and clean up.

Environment dependencies

  • Network calls: Tests hit real services that may be slow or unavailable. Fix: mock network calls.
  • Date/time sensitivity: Tests depend on current time or tim
FAQ

How does it find flaky tests?

It lists tests flagged as flaky in Tuist's test insights.

What if no test is given?

It discovers the flaky tests in the project and groups them by suite.

How does it confirm a fix?

It runs the test several times to check that it passes consistently.

Details

Original description by the author

Fixes flaky tests by analyzing failure patterns from Tuist test insights, identifying root causes, and applying targeted corrections. Can be invoked with a specific test case URL (e.g. `https://tuist.dev/{account}/{project}/tests/test-cases/{id}`) or without arguments to discover and fix all flaky tests in the project.

repo: tuist/tuist

Popularity

GitHub stars
5.9k
Ranking position
#14544
License
β€”
Updated
11/2/2026

Is this skill useful?

0

Sign in to vote.

Comments

  • …

More skills from this repository

Similar skills