Skip to content

Xcode Flaky Tests

::: warning REQUIREMENTS

  • Test Insights must be configured

:::

Flaky tests are tests that produce different results (pass or fail) when run multiple times with the same code. They erode trust in your test suite and waste developer time investigating false failures. Tuist automatically detects flaky tests and helps you track them over time.

Flaky Tests page

Tuist detects flaky tests in two ways:

When you run tests with retry functionality, Tuist analyzes the results of each attempt. If a test fails on some attempts but passes on others, it’s marked as flaky.

Use -retry-tests-on-failure or -test-iterations:

Terminal window
tuist xcodebuild test \
-scheme MyScheme \
-retry-tests-on-failure \
-test-iterations 3

Flaky test case detail

Cross-run detection {#cross-run-detection}

Section titled “Cross-run detection {#cross-run-detection}”

Even without test retries, Tuist can detect flaky tests by comparing results across different CI runs on the same commit. If a test passes in one CI run but fails in another run for the same commit, both runs are marked as flaky.

This is particularly useful for catching flaky tests that don’t fail consistently enough to be caught by retries, but still cause intermittent CI failures.

Managing flaky tests {#managing-flaky-tests}

Section titled “Managing flaky tests {#managing-flaky-tests}”

Tuist automatically clears the flaky flag from tests that haven’t been flaky for 14 days. This ensures that tests that have been fixed don’t remain marked as flaky indefinitely.

You can also manually mark or unmark tests as flaky from the test case detail page. This is useful when:

  • You want to acknowledge a known flaky test while working on a fix
  • A test was incorrectly flagged due to infrastructure issues

Quarantining allows you to isolate flaky tests so they don’t block your CI pipeline while you work on fixing them. Quarantined tests can be skipped during test runs, preventing false failures from disrupting your team’s workflow.

[!IMPORTANT] Unless you’re using tuist test, quarantining a test does not automatically skip it. You must explicitly pass the list of quarantined tests to xcodebuild using the -skip-testing flag.

When enabled in your project’s Automations settings, tests are automatically quarantined when they’re marked as flaky. This ensures that newly detected flaky tests are immediately isolated without manual intervention.

To enable automatic quarantine:

  1. Go to your project settings
  2. Navigate to the Automations tab
  3. Enable Auto-quarantine flaky tests

You can also manually quarantine or unquarantine tests from the test case detail page using the Quarantine and Unquarantine buttons. This is useful when:

  • You want to quarantine a test before it’s automatically detected as flaky
  • You want to unquarantine a test after fixing the underlying issue

Skipping quarantined tests {#skipping-quarantined-tests}

Section titled “Skipping quarantined tests {#skipping-quarantined-tests}”

When you run tuist test, quarantined tests are automatically skipped. Tuist fetches the list of quarantined tests from the server and passes them to xcodebuild using the -skip-testing flag.

Terminal window
tuist test

If you want to run all tests including quarantined ones, use the --skip-quarantine flag:

Terminal window
tuist test --skip-quarantine

If you’re using xcodebuild directly instead of tuist test, use the tuist test case list command with the --skip-testing flag to get quarantined test identifiers formatted for xcodebuild:

Terminal window
xcodebuild test \
-scheme MyScheme \
$(tuist test case list --skip-testing)

Slack notifications {#slack-notifications}

Section titled “Slack notifications {#slack-notifications}”

Get notified instantly when a test becomes flaky by setting up flaky test alerts in your Slack integration.