Auto rerun failed tests Beta
|
Smarter Testing is available in beta. This means the product is in early stages and you may encounter bugs, unexpected behavior, or incomplete features. When the feature is made generally available, there will be a cost associated with access and usage. Refer our Discuss post for more information about our beta launch. |
Auto rerun failed tests automatically detects and retries test failures during your test run. Compared with the existing Rerun Failed Tests feature that CircleCI provides, Auto rerun failed tests eliminates the need to:
-
Manually identify which jobs failed.
-
Manually select the Rerun failed tests option in the CircleCI web app.
Is my project a good fit for auto rerun failed tests?
Auto rerun failed tests reruns tests within the same step automatically until all tests pass or the maximum rerun attempts is reached.
If your test suite has flaky tests, auto rerun can quickly recover from test failures without rerunning your entire test suite.
How it works
All tests are run as normal with the discover and run command.
When auto rerun failed tests is enabled:
-
Any test results that failed in the JUnit XML output are rerun.
-
The process repeats until all tests are successful, or the maximum number of rerun attempts is reached.
-
If all tests are successful, 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:
-
Installed the
testsuiteCLI plugin. -
Configured your
.circleci/test-suites.ymlwithdiscoverandruncommands. -
Verified your tests run successfully with the
testsuitecommand. -
Correctly configured JUnit XML output in
.circleci/test-suites.yml.
1. Enable auto rerun failed tests option in your .circleci/test-suites.yml file
---
name: ci tests
# ...
options:
max-auto-rerun: 3
| Options Field | Default | Description |
|---|---|---|
|
0 |
The maximum number of times tests will be rerun if they fail. When |
|
null |
The duration or percentage of total runtime tests will be rerun if they fail, for example, When |
2. Run locally
Use --doctor locally to validate the test-suites.yml is set up correctly.
The CLI will run through additional checks when auto rerun is enabled, if any results look incorrect an action item is provided to resolve it. Follow the steps until all checks pass.
$ circleci run testsuite "ci tests" --doctor
|
The The testsuite will automatically find the |
Modify a test to cause it to fail and check that the test is rerun locally by removing the --doctor flag.
$ circleci run testsuite "ci tests"
3. Run in CI
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 looking at the "Test" tab in the UI.
Next steps
-
Set up Test Impact Analysis to run only impacted tests based on code changes.
-
Use Dynamic Test Splitting to evenly split tests across parallel nodes.