Auto rerun failed tests
Auto rerun failed tests automatically detects and retries test failures during your test run. Compared with manually Rerunning Failed Tests from a workflow, auto rerun failed tests eliminates the need to:
-
Manually identify which jobs failed.
-
Manually select Rerun workflow from failed in the CircleCI web app.
| Test impact analysis, dynamic test splitting, dynamic parallelism, and auto rerun failed tests have a credit charge above your plan’s allowance. See Credit Charge. |
Is my project a good fit for auto rerun failed tests?
This section outlines several project features that indicate your project is a good candidate for auto rerun failed tests:
How it works
All test atoms are run as normal with the discover and run commands.
When auto rerun failed tests is enabled:
-
Any test atoms that failed in the JUnit XML output are rerun.
-
The process repeats until all test atoms pass, or the maximum number of rerun attempts is reached.
-
If all test atoms pass, the errors are suppressed and the job succeeds.
-
If the maximum number of reruns is reached and there are still test failures, the job fails.
Prerequisites
Before enabling auto rerun failed tests, ensure you have completed the Getting Started With Smarter Testing guide and have:
-
Configured your
.circleci/test-suites.ymlwithdiscoverandruncommands. -
Verified your tests run successfully with the
testsuitecommand. -
Correctly configured JUnit XML output in
.circleci/test-suites.yml.
| You can use the CircleCI Agent Skills to get Smarter Testing set up. Install the CircleCI Public Skills plugin to your AI coding agent and ask your agent to get set up for Smarter Testing. |
This page covers max-auto-rerun in .circleci/test-suites.yml, which retries individual failed test atoms as part of Smarter Testing. If you want to retry entire steps or workflows, see Automatic Reruns, which uses the separate max_auto_reruns key in .circleci/config.yml.
|
1. Enable auto rerun failed tests in your .circleci/test-suites.yml file
Add the max-auto-rerun option to your .circleci/test-suites.yml:
---
name: ci tests
# ...
options:
max-auto-rerun: 3
| Options Field | Default | Description |
|---|---|---|
|
0 |
The maximum number of times test atoms are rerun if they fail. Accepts a value in the range 0 to 10 inclusive. When |
|
null |
The duration or percentage of total runtime to spend rerunning failed test atoms, for example, When |
2. Run
Use the doctor command to validate that your test-suites.yml is set up correctly. The CLI runs additional checks when auto rerun is enabled. If any results look incorrect, an action item is provided to resolve it.
$ circleci testsuite doctor "ci tests"
Follow the steps until all checks pass.
|
Run the The testsuite will look for the |
To verify auto rerun locally, modify a test to cause it to fail, then run the test suite:
$ circleci testsuite run "ci tests"
Commit .circleci/test-suites.yml to your feature branch and push to your VCS.
Verify auto rerun failed tests is working as expected in CI by checking the Tests tab in the CircleCI web app.
Next steps
-
Set Up Test Impact Analysis to run only the tests impacted by your code changes.
-
Use Dynamic Test Splitting to evenly split tests across parallel nodes.