NUnitRetry SpecFlow Plugin is the newest approach to adding "Nunit.Framework.Retry" attribute to SpecFlow's generated tests. It's based on Josh Keegan xRetry (https://github.com/JoshKeegan/xRetry). It's intention is to mimic SpecFlow+ Runner's re-running abilities. It's main features are:
Flaky tests. This plugin is here to help you with tests, which's 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!
"NRetrySettings": {
"maxRetries": 3,
"applyGlobally": true
}
@Retry
tag is used.You can also make every test in a feature retryable by adding the @Retry
tag to the feature, e.g:
@Retry
Feature: Retryable Feature
Scenario: Retry scenario three times by default
When I increment the retry count
Then the result should be 3
@Retry(5)
Feature: Retryable Feature
Scenario: Retry scenario five times
When I increment the retry count
Then the result should be 5
All options that can be used against an individual scenario can also be applied like this at the feature level.
If a @Retry
tag exists on both the feature and a scenario within that feature, the tag on the scenario will take
precedent over the one on the feature. This is useful if you wanted all scenarios in a feature to be retried
by default but for some cases also wanted to wait some time before each retry attempt. You can also use this to prevent a specific scenario not be retried, even though it is within a feature with a @Retry
tag, by adding @Retry(1)
to the scenario.
Above any scenario or scenario outline that should be retried, add a @retry
tag, e.g:
Feature: Retryable Feature
@Retry
Scenario: Retry scenario three times by default
When I increment the retry count
Then the result should be 3
Feature: Retryable Feature
@Retry(5)
Scenario: Retry scenario five times
When I increment the retry count
Then the result should be 5
This will attempt to run the test until it passes, up to 3 times by default (or else, as its based on config located in specflow.json).
You can optionally specify a number of times to attempt to run the test in brackets, e.g. @Retry(5)
.
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.
As this plugin is currently in development state, the installation requires you to follow this steps:
Example usage is presented in included NunitRetrySpecFlowTests.