DETECTION · 8 MIN READ

How to Detect Flaky Tests Automatically in CI/CD Pipelines

Step-by-step guide to flaky test detection using rerun tracking, flip-rate statistics, Wilson confidence intervals, JUnit XML, and CTRF.

Why Manual Flake Hunting Fails at Scale

Searching CI logs by hand only catches the loudest failures. Subtle flaky tests that fail 3% of the time slip past individual developers because each engineer sees the failure once, hits retry, and moves on. Across a 30-engineer team, a 3% flake across 20 tests means nearly half of all pull requests experience a spurious failure.

Automated flaky test detection requires structured attempt-level telemetry across every CI execution, normalized across frameworks like Jest, Vitest, Playwright, Pytest, Mocha, Go test, JUnit XML, and CTRF.

Combining Rerun Signals and Historical Flip Rates

The gold standard for proving a test is flaky is observing both a FAILED and a PASSED attempt on the exact same commit SHA and environment fingerprint. When your runner retries failed tests automatically (for example Playwright retries: 2 or pytest-rerunfailures), FlakeCheck captures every attempt and flags proven flakes with 100% confidence.

For suites without inline retries, historical flip-rate analysis tracks pass-to-fail and fail-to-pass transitions across consecutive runs where the test file did not change. Applying a Wilson score 95% confidence interval and a minimum sample size prevents newly added tests with one transient failure from triggering false alarms.

# .github/workflows/ci.yml
- name: Run tests with retries and JUnit output
  run: pnpm test --reporter=junit --outputFile=junit.xml
  continue-on-error: true

- name: Detect flaky tests with FlakeCheck
  uses: ./ci-templates/github-action
  with:
    gateway-url: ${{ secrets.FLAKECHECK_URL }}
    token: ${{ secrets.FLAKECHECK_TOKEN }}
    format: junit
    files: junit.xml

Standardizing on JUnit XML and CTRF

Polyglot repositories mix TypeScript, Python, Go, and Java test runners. Instead of maintaining fragile custom scripts per language, FlakeCheck natively parses JUnit XML and the Common Test Report Format (CTRF) alongside native JSON outputs for Jest, Vitest, Playwright, Pytest, Mocha, and Go test.

CTRF is especially valuable because it explicitly records retry counts, flaky flags, file paths, and error traces in a single portable JSON schema.

Verifying Your Setup with the CLI Doctor

Before rolling out flaky test detection across all repositories, run flakecheck doctor --json locally or in a CI job to verify gateway connectivity, Neon PostgreSQL readiness, repository token scope, and Git metadata resolution.

flakecheck init --gateway https://flakecheck.onurd.com.tr --repo acme/app --token "$FLAKECHECK_TOKEN"
flakecheck doctor --json

Eliminate flaky tests automatically with FlakeCheck

Stream your JUnit, CTRF, Jest, Vitest, Playwright, Pytest, Mocha, or Go reports to FlakeCheck and get statistical scoring + auto-quarantine in minutes.

Related Guides