All Projects → JoshKeegan → xRetry

JoshKeegan / xRetry

Licence: MIT License
Retry running tests via Xunit and Specflow

Programming Languages

C#
18002 projects
Gherkin
971 projects
Makefile
30231 projects
shell
77523 projects

Projects that are alternatives of or similar to xRetry

arduino-ci-script
Bash script for continuous integration of Arduino projects
Stars: ✭ 25 (+66.67%)
Mutual labels:  test, test-automation
kekiri
A .NET framework that supports writing low-ceremony BDD tests using Gherkin language
Stars: ✭ 19 (+26.67%)
Mutual labels:  xunit, specflow
eat
Json based scenario testing tool(which can have test for functional and non-functional)
Stars: ✭ 41 (+173.33%)
Mutual labels:  test, test-automation
Swagger meqa
Auto generate and run tests using swagger/OpenAPI spec, no coding needed
Stars: ✭ 151 (+906.67%)
Mutual labels:  test, test-automation
action-junit-report
Reports junit test results as GitHub Pull Request Check
Stars: ✭ 103 (+586.67%)
Mutual labels:  test, test-automation
Hitchhiker
a Restful Api test tool
Stars: ✭ 2,175 (+14400%)
Mutual labels:  test, test-automation
carina
Carina automation framework: Web, Mobile, API, DB etc testing...
Stars: ✭ 652 (+4246.67%)
Mutual labels:  test, test-automation
Testcafe
A Node.js tool to automate end-to-end web testing.
Stars: ✭ 9,176 (+61073.33%)
Mutual labels:  test, test-automation
powerapps-specflow-bindings
A SpecFlow bindings library for model-driven Power Apps.
Stars: ✭ 19 (+26.67%)
Mutual labels:  specflow, test-automation
IO-TESTER
A functional test framework
Stars: ✭ 32 (+113.33%)
Mutual labels:  test, test-automation
CodeSpecJS
UI Automation Testing without writing a single line of code
Stars: ✭ 16 (+6.67%)
Mutual labels:  test, test-automation
Example
Example collections of PocoAndroid, Unity3d demo game and etc...
Stars: ✭ 17 (+13.33%)
Mutual labels:  test, test-automation
Ztest
自动化测试报告
Stars: ✭ 143 (+853.33%)
Mutual labels:  test, test-automation
Ocaramba
C# Framework to automate tests using Selenium WebDriver
Stars: ✭ 234 (+1460%)
Mutual labels:  test, test-automation
Test Each
🤖 Repeat tests. Repeat tests. Repeat tests.
Stars: ✭ 89 (+493.33%)
Mutual labels:  test, test-automation
jest-retry
Jest retry pattern for flaky E2E tests
Stars: ✭ 36 (+140%)
Mutual labels:  test, test-automation
Cypress
Fast, easy and reliable testing for anything that runs in a browser.
Stars: ✭ 35,145 (+234200%)
Mutual labels:  test, test-automation
Powerslim
Fitnesse Slim implementation in PowerShell. PowerSlim makes it possible to use PowerShell in the acceptance testing
Stars: ✭ 49 (+226.67%)
Mutual labels:  test, test-automation
Telegraf-Test
Telegraf Test - Simple Test ToolKit of Telegram Bots
Stars: ✭ 22 (+46.67%)
Mutual labels:  test, test-automation
Wasmite
Now WebAssembly has proper testing, unit-testing and debugging 🤗
Stars: ✭ 20 (+33.33%)
Mutual labels:  test, test-automation

xRetry

Retry flickering test cases for xUnit and SpecFlow in dotnet.

pipeline status

When to use this

This is intended for use on flickering tests, where the reason for failure is an external dependency and the failure is transient, e.g:

  • HTTP request over the network
  • Database call that could deadlock, timeout etc...

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!

Usage: SpecFlow 3

Add the xRetry.SpecFlow nuget package to your project.

Above any scenario or scenario outline that should be retried, add a @retry tag, e.g:

@retry
Scenario: Retry three times by default
	When I increment the default retry count
	Then the default result should be 3

This will retry the test up to 3 times by default. You can optionally specify a number of times to retry the test in brackets, e.g. @retry(5).

You can also optionally specify a delay between each retry (in milliseconds) as a second parameter, e.g. @retry(5,100) will run your test 5 times until it passes, waiting 100ms between each attempt.
Note that you must not include a space between the parameters, as Cucumber/SpecFlow uses a space to separate tags, i.e. @retry(5, 100) would not work due to the space after the comma.

Usage: xUnit

Add the xRetry nuget package to your project.

Facts

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 retry the test up to 3 times by default. You can optionally specify a number of times to retry 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 5 times until it passes, waiting 100ms between each attempt.

Theories

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 retries and delay between each retry) are supported as for facts, and can be used in the same way.

Skipping tests at Runtime

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.

Viewing retry logs

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.

Contributing

Feel free to open a pull request! If you want to start any sizeable chunk of work, consider opening an issue first to discuss, and make sure nobody else is working on the same problem.

Running locally

To run locally, always build xRetry.SpecFlowPlugin before the tests, to ensure MSBuild uses the latest version of your changes.

If you install make and go to the build directory, you can run the following from the terminal to build, run tests and create the nuget packages:

make ci

If that works, all is well!

Licence

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].