Rerun only the failed .NET tests, automatically, until they pass.
dotnet test has no built-in way to retry failed tests. dotnet-test-rerun wraps it: it runs your tests, reads the TRX results to find the failed ones, and runs only those again, up to --rerunMaxAttempts times. It works with xUnit, NUnit and MSTest, and accepts the same options as dotnet test.
Use it to keep CI green when tests fail for reasons outside your code: a database that is still starting, a rate-limited API, a slow browser in a UI test.
dotnet tool install --global dotnet-test-rerun
# Run the tests, then rerun the failed ones up to 3 times (the default)
test-rerun path/to/MyTests.csproj
# Rerun up to 5 times, waiting 10 seconds before each rerun
test-rerun path/to/MyTests.csproj --rerunMaxAttempts 5 --delay 10The path can be anything dotnet test accepts: a project, a solution, a directory or a test .dll.
run 1 dotnet test ... → 120 passed, 3 failed
run 2 dotnet test ... --filter "<the 3 failed tests>" → 2 passed, 1 failed
run 3 dotnet test ... --filter "<the 1 failed test>" → 1 passed
exit code 0
- Every run writes its TRX files to
--results-directory. Each run only reads the files it created. - If you pass
--filter, it is kept on every rerun:(your filter)&(failed tests). - Use
--rerunMaxFailedTestsor--rerunFailedThresholdto skip reruns when too many tests fail, because that usually means a real problem. - The exit code is
0if every test passed in the end, and1otherwise.
More detail: How it works.
| Option | Default | Description |
|---|---|---|
--rerunMaxAttempts |
3 |
Maximum number of reruns after the first run |
--rerunMaxFailedTests |
-1 (no limit) |
Do not rerun if more tests than this failed |
--rerunFailedThreshold |
-1 (no limit) |
Do not rerun if more than this percentage of tests failed |
--delay, -d |
0 |
Seconds to wait before each rerun |
--results-directory, -r |
. |
Where results go |
--mergeCoverageFormat |
— | Merge the coverage of all runs (Coverage, Cobertura, Xml); needs dotnet-coverage |
--logTestResults |
false |
Print the result of each test as soon as it finishes |
--generateTestCommand |
false |
At the end, print a dotnet test command that runs only the tests still failing |
--deleteReports |
false |
Delete the TRX files when finished |
--filter, --logger, --settings, --configuration, --framework, --no-build, --blame, --collect, -e, /p: and inline run settings are passed to dotnet test. See the command reference for all options.
# GitHub Actions
- run: dotnet build --configuration Release
- uses: joaoopereira/dotnet-test-rerun@v5
with:
path: MySolution.sln
arguments: --no-build --configuration Release
upload-results: trueAction inputs, a script-based setup, and the Azure DevOps and GitLab CI examples: CI integration.
docker run --rm -v "$PWD:/src" -w /src joaoopereira/dotnet-test-rerun:latest MyTests.csprojTags: latest and <version> (.NET 10), <version>-net10, <version>-net8. See the Docker guide.
Bug reports, ideas and pull requests are welcome. Read the contributing guide and browse the open issues.
Copyright © 2023-2026 João Pereira. Licensed under the GNU General Public License v3.0.