Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Retry for failed tests only #1828

Closed
assapir opened this issue Oct 10, 2016 · 11 comments
Closed

Add Retry for failed tests only #1828

assapir opened this issue Oct 10, 2016 · 11 comments
Assignees
Milestone

Comments

@assapir
Copy link

assapir commented Oct 10, 2016

Is it possible somehow?

@CharliePoole
Copy link
Contributor

NUnit includes a RetryAttribute for tests that should be retried up to a maximum number of times if they fail. Please review the documentation.

@assapir
Copy link
Author

assapir commented Oct 19, 2016

This is working only for tests without parameters. Is there any why to pass a parameters when we are using retry?

@CharliePoole
Copy link
Contributor

If it isn't working for a particular use case we can reopen this issue. Please provide an example.

@assapir
Copy link
Author

assapir commented Oct 19, 2016

This is the documentation on https://github.com/nunit/docs/wiki/Retry-Attribute :
"Since a parameterized test method represents a suite, RetryAttribute is ignored when it appears on such a method."

@CharliePoole
Copy link
Contributor

@meijin007 Thanks for reminding me of that restriction, which I had forgotten. I'll reopen this and take a closer look.

@CharliePoole
Copy link
Contributor

The documentation statement was a hold-over from NUnit 2 and is not correct. I have added a test to verify that Retry works on Test Cases. Note that the retry applies to each test case when used this way.

@ammark1
Copy link

ammark1 commented Dec 14, 2017

Hi @CharliePoole , I am facing a problem with Retry Attribute. NUnit is retaining the previous Failed value in
TestContext.CurrentContext.Result.Outcome and hence my Test Case is Failed even if it is actually Passed in the second attempt. Please see the below code snippet, my code goes inside the First if loop because currentContext.Result.Outcome value is "Failed" in the second attempt as well in the TearDown method(although my Test gets passed during the second attempt):

[TearDown]
public void TearDown()
{
try
{
var currentContext = TestContext.CurrentContext;
var message = TestContext.CurrentContext.Result.Message;
var stackTrace = TestContext.CurrentContext.Result.StackTrace;
if (currentContext.Result.Outcome != ResultState.Success)
{
var testName = currentContext.Test.Name;
string rootPath = AppDomain.CurrentDomain.BaseDirectory;
String filename = rootPath+"\Report\" + this.GetType().FullName + "." + testName + "_" + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".png";
Console.WriteLine("filename: " + filename);
UtilityHelper.TakeScreenshot(_driver, filename);
if (Global.tempCount <= 1)
Global.test.Log(Status.Fail, stackTrace + message);
}
Log.Info("Teardown test");
_driver.Quit();
}
catch { _driver.Dispose(); }
}

@CharliePoole
Copy link
Contributor

@ammark1 This specific issue was fixed and has been closed for a while. If you have a new problem, it's best to file a new issue.

@ammark1
Copy link

ammark1 commented Dec 14, 2017

@CharliePoole New ticket created: #2619

@lakshmikrishnamurthy30
Copy link

Hi ,

By using Retry functionality, is it possible to rerun all failed tests at the end instead of immediately after the failed test?

@ChrisMaddock
Copy link
Member

Not currently, no.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

6 participants