I am trying to Re-run failed Nunit tests, mainly because of flackiness with selenium.
[TearDown]
public virtual void TearDown()
{
var testName = TestContext.CurrentContext.Test.FullName.Replace("Server.Tests.", string.Empty);
if (TestContext.CurrentContext.Result.Status == TestStatus.Passed)
return;
else if (_testFailure < 3) {
_testFailure++;
Console.WriteLine($"\n {testName} {TestContext.CurrentContext.Result.Status}... Retrying attempt {_testFailure}");
DbReloader.LoadUnitTestData(DbFactory);
TestExecutionContext.CurrentContext.CurrentTest.Run(new NullListener(), TestFilter.Empty);
}
BrowserDriver.GetScreenshot()
.SaveAsFile($"{testName}.fail.png", ImageFormat.Png);
}
The problem is after the test runs again, it will continue with the tear down of the test as the original test failed. How do I override the TestContext.CurrentContext.Result with my retried test results?