Documentation

Automated flaky test detection in CI test runs

TestNod's flaky test detection tracks how often each test fails, or passes only on a retry, across your recent CI runs. It fires an alert when that rate reaches the threshold you set. Every new test run with at least one failure or one test that passed on retry gets checked, including builds that went green because of a retry.

What triggers the flakiness alert

When a test run finishes processing with at least one failed test case or one that passed on retry, TestNod takes the 20 most recent processed runs in the project that share the same set of tags as the new run. For each of those cases, it counts how many of the 20 runs included that test and how many of them recorded the test as either failed or passed on retry.

The alert fires when:

failure_count / total_count >= threshold / 100

The default threshold is 30%.

For example, if a test was present in all 20 of the most recent same-tag runs and failed in 6 of them, the alert triggers the next time the same test fails.

Flaky tests that pass on retry

If a test fails and then passes on a later attempt in the same build, TestNod marks it passed on retry and keeps the failure message from the failed attempt. Those runs count toward the failure rate the same way failures do, so a test that only passes because of your retries still triggers this alert. The event lists how many of the counted runs were retries, which tells you whether the test fails outright or needs a second attempt. To get rerun results into TestNod, see Retries and reruns.

The 20-run baseline

Flaky test detection needs at least 20 processed runs on the same set of tags before it can fire on a project, and runs on a tag set with less history than that aren't checked. As newer runs come in and older ones drop off, the window rolls forward and the rate adjusts to recent behavior.

Example: detecting a flaky test

Your project tags every CI run with ci and unit and uses the default 30% threshold. A new run finishes, and the test OrderProcessingTest::handles_bulk_orders fails. TestNod looks at the last 20 runs that share the ci, unit tag set, sees that the same test has been included in all of them and failed in 7 (35%), and fires the alert because that rate is above the 30% threshold. The event records 35%, the 7-of-20 counts, the failure message from the new run, and the tag set used for the comparison.

What the alert event shows

When the alert fires, the event recorded against it shows the test that triggered it, the failure rate across the window, the raw counts behind that rate, the most recent failure message, and the tag set used for the comparison. The alert detail page links back to the triggering run so you can open it and see the failure in context.

Alert detail page for a test flakiness alert showing the failure rate, the 7-of-20 counts, the recent failure message, and a link to the triggering run

Reading the failure rate

A 30% rate from 6 failures across 20 runs means something different from a 30% rate from 3 failures across 10 runs, so TestNod shows both counts on the event. A high rate over a small count usually means the test is newer or only runs in some configurations, while a high rate over a large count means the test is a chronic flake.

Tuning the flakiness threshold

Two common reasons to adjust the default 30%:

  • Too many borderline misses. Lower the threshold to 10–20% if you want every test that occasionally fails to show up. Expect a longer initial list as the check finds flakes that were already there.
  • Only chronic flakes matter. Raise the threshold to 50% if you only want alerts for tests that fail at least half the time.

Project admins set the threshold from the alert configuration page. See Configuring alerts for the walkthrough.

Alert configuration row for test flakiness showing the threshold input set to 30%

What the alert does not catch

  • A test that always fails. That's a broken test, and the What Changed panel lists it on the first run it fails.
  • Cross-tag flakes. Tag matching is exact. A test that flakes in smoke runs but holds steady in integration runs triggers the alert only on smoke runs.
  • First-time failures. A test that hasn't appeared in the previous 20 runs has no history to measure against, so it can't trigger the alert on its first observed failure.
  • Errored tests. TestNod treats errors as environment or infrastructure issues, so a case that errors out doesn't count toward the failure rate. The exception is a test that errors and then passes on a retry in the same build. It counts as passed on retry, since it recovered without anyone changing the code.

Enabling flaky test detection

An admin turns on the flakiness alert and sets its threshold from the alert configuration page. Once a tag set has 20 runs of history, every run on it with at least one failed test case, or one that passed on retry, is checked, and any test that crosses the threshold records an event on the alert detail page and sends a notification email to project members who haven't opted out.

Start tracking your test runs

The Solo plan is free for one project and 250 test runs a month, and you don't need a credit card to sign up.

Sign up free