我正在尝试重新运行失败的 Nunit 测试,主要是因为硒的脆弱性。
[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);
}
问题是在测试再次运行后,由于原始测试失败,它将继续拆除测试。如何用重试的测试结果覆盖 TestContext.CurrentContext.Result?