Hello I want to pass the number of retries dynamically from app.config value.
The app.config has the following line:
While I am not fully aware of the RetryAttribute. One possible way of achieving the desired functionality would be to extend its current functionality.
///
/// RetryDynamicAttribute may be applied to test case in order
/// to run it multiple times based on app setting.
///
[AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)]
public class RetryDynamicAttribute : RetryAttribute {
private const int DEFAULT_TRIES = 1;
static Lazy numberOfRetries = new Lazy(() => {
int count = 0;
return int.TryParse(ConfigurationManager.AppSettings["retryTest"], out count) ? count : DEFAULT_TRIES;
});
public RetryDynamicAttribute() :
base(numberOfRetries.Value) {
}
}
And then apply the custom attribute.
[Test]
[RetryDynamic]
public void Test() {
//....
}