![]() |
VOOZH | about |
dotnet add package xRetry --version 1.9.0
NuGet\Install-Package xRetry -Version 1.9.0
<PackageReference Include="xRetry" Version="1.9.0" />
<PackageVersion Include="xRetry" Version="1.9.0" />Directory.Packages.props
<PackageReference Include="xRetry" />Project file
paket add xRetry --version 1.9.0
#r "nuget: xRetry, 1.9.0"
#:package xRetry@1.9.0
#addin nuget:?package=xRetry&version=1.9.0Install as a Cake Addin
#tool nuget:?package=xRetry&version=1.9.0Install as a Cake Tool
Retry flickering test cases for xUnit.
This is intended for use on flickering tests, where the reason for failure is an external dependency and the failure is transient, e.g:
Whenever a test includes real-world infrastructure, particularly when communicated with via the internet, there is a risk of the test randomly failing so we want to try and run it again. This is the intended use case of the library.
If you have a test that covers some flaky code, where sporadic failures are caused by a bug, this library should not be used to cover it up!
Add the xRetry nuget package to your project.
Above any Fact test case that should be retried, replace the Fact attribute, with
RetryFact, e.g:
private static int defaultNumCalls = 0;
[RetryFact]
public void Default_Reaches3()
{
defaultNumCalls++;
Assert.Equal(3, defaultNumCalls);
}
This will attempt to run the test until it passes, up to 3 times by default.
You can optionally specify a number of times to attempt to run the test as an argument, e.g. [RetryFact(5)].
You can also optionally specify a delay between each retry (in milliseconds) as a second
parameter, e.g. [RetryFact(5, 100)] will run your test up to 5 times, waiting 100ms between each attempt.
If you have used the library for retrying Fact tests, using it to retry a Theory should be very intuitive.
Above any Theory test case that should be retried, replace the Theory attribute with RetryTheory, e.g:
// testId => numCalls
private static readonly Dictionary<int, int> defaultNumCalls = new Dictionary<int, int>()
{
{ 0, 0 },
{ 1, 0 }
};
[RetryTheory]
[InlineData(0)]
[InlineData(1)]
public void Default_Reaches3(int id)
{
defaultNumCalls[id]++;
Assert.Equal(3, defaultNumCalls[id]);
}
The same optional arguments (max attempts and delay between each retry) are supported as for facts, and can be used in the same way.
In addition to retries, RetryFact and RetryTheory both support dynamically skipping tests at runtime. To make a test skip just use Skip.Always()
within your test code.
It also supports custom exception types so you can skip a test if a type of exception gets thrown. You do this by specifying the exception type to the
attribute above your test, e.g.
[RetryFact(typeof(TestException))]
public void CustomException_SkipsAtRuntime()
{
throw new TestException();
}
This functionality also allows for skipping to work when you are already using another library for dynamically skipping tests by specifying the exception
type that is used by that library to the RetryFact. e.g. if you are using the popular Xunit.SkippableFact nuget package and want to add retries, converting the
test is as simple as replacing [SkippableFact] with [RetryFact(typeof(Xunit.SkipException))] above the test and you don't need to change the test itself.
By default, you won't see whether your tests are being retried as we make this information available
via the xunit diagnostic logs but test runners will hide these detailed logs by default.
To enable them you must configure your xUnit test project to have diagnosticMessages set to true in the xunit.runner.json.
See the xUnit docs for a full setup guide of their config file, or see
this projects own unit tests which has been set up with this enabled.
If you find a bug whilst using this library, please report it on GitHub.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 was computed. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net452 net452 is compatible. net46 net46 was computed. net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 was computed. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 2 NuGet packages that depend on xRetry:
| Package | Downloads |
|---|---|
|
xRetry.SpecFlow
Allows for a @retry(n) tag to be placed above scenarios in SpecFlow.XUnit. This can be used to re-run a failed test up to n times, allowing for transient failures (e.g. network related) to be tolerated. |
|
|
xRetry.Reqnroll
Allows for a @retry(n) tag to be placed above scenarios in Reqnroll.xUnit. This can be used to re-run a failed test up to n times, allowing for transient failures (e.g. network related) to be tolerated. |
Showing the top 11 popular GitHub repositories that depend on xRetry:
| Repository | Stars |
|---|---|
|
microsoft/semantic-kernel
Integrate cutting-edge LLM technology quickly and easily into your apps
|
|
|
alirezanet/Gridify
Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.
|
|
|
planetarium/libplanet
Blockchain in C#/.NET for on-chain, decentralized gaming
|
|
|
OpenCoreMMO/OpenCoreMMO
Modern MMORPG server emulator written in C#
|
|
|
joelverhagen/TorSharp
Use Tor for your C# HTTP clients. Use Privoxy or .NET 6+ SOCKS support to proxy HTTP traffic.
|
|
|
gpailler/MegaApiClient
MegaApiClient is a C# .Net library to access http://mega.co.nz / http://mega.nz cloud storage and file hosting service.
|
|
|
CommunityToolkit/Datasync
A collection of libraries that implement a client-server system used for synchronizing data from a cloud-based database.
|
|
|
kurrent-io/KurrentDB-Client-Dotnet
KurrentDB .NET Client
|
|
|
Viincenttt/MollieApi
This project allows you to easily add the Mollie payment provider to your application.
|
|
|
Azure/azure-functions-sql-extension
Azure SQL bindings for Azure Functions ⚡️ supports Azure SQL Database, Azure SQL Managed Instance, and SQL Server 2016+
|
|
|
timonkrebs/MemoizR
Declarative Structured Concurrency for C#
|
| Version | Downloads | Last Updated |
|---|---|---|
| 1.9.0 | 6,564,668 | 1/1/2023 |
| 1.9.0-alpha1 | 1,808 | 12/19/2022 |
| 1.8.0 | 1,054,149 | 2/26/2022 |
| 1.7.0 | 307,246 | 10/30/2021 |
| 1.6.0 | 204,538 | 6/23/2021 |
| 1.5.0 | 127,296 | 5/12/2021 |
| 1.4.1 | 332,156 | 2/23/2021 |
| 1.4.0 | 4,094 | 2/16/2021 |
| 1.3.0 | 36,825 | 1/22/2021 |
| 1.2.0 | 12,999 | 11/13/2020 |
| 1.1.0 | 31,983 | 8/19/2020 |
| 1.0.0 | 10,395 | 6/27/2020 |
| 0.5.0 | 43,118 | 4/10/2020 |
| 0.5.0-alpha1 | 1,462 | 3/27/2020 |
| 0.4.1 | 2,695 | 3/26/2020 |
| 0.4.1-alpha | 1,497 | 3/26/2020 |
| 0.4.0 | 2,600 | 3/10/2020 |
| 0.3.2 | 4,985 | 8/2/2019 |
| 0.3.1 | 2,246 | 6/24/2019 |
| 0.3.0 | 2,129 | 5/22/2019 |