NUnit 3 - 重试失败时不被调用
NUnit 3 - retry not being called on fail
我对 NUnit 重试属性有疑问
我们正在使用
NUnit 3.12.0
NUnit3TestAdapter 3.17.0
C# and Selenium
这是一个典型的特征文件
Test.feature
Scenario Template: 01 Test footer options - Homeowner
Given we set the destination to the homepage
When we select footer option "1"
Then we should see the url "tester" and title "test page"
这就是钩子
Hooks.cs
[BeforeFeature(Order = 1)]
[Test, Retry(2)]
public static void BeforeFeatureTab(FeatureContext featureContext)
{
etc
}
我们在这里捕获了故障
public void AssertUrlContains(string comparing, IWebDriver driver)
{
var currentUrl = driver.Url;
try
{
WriteToReport(Status.Pass, "Pass: URL is correct");
Assert.That(currentUrl.Contains(comparing));
}
catch (Exception ex)
{
WriteToReport(Status.Fail, "Fail error: " + ex);
Assert.That(false);
}
}
现在我认为 Assert.That(false) 会触发重试,但现在是。谁能看到我做错了什么或错过了什么感到高兴。
谢谢
凯夫
虽然你没有标记它,但我假设你正在使用 SpecFlow。虽然我对它不是很了解,但我从帮助使用 NUnit 的人那里学到了一些东西。也就是说,这就是我的想法...
BeforeFeatureAttribute
转换为 NUnit OneTimeSetUpAttribute
(以前称为 TestFixtureSetUpAttribute
,在任何测试之前调用 运行。OTOH,TestAttribute
表示方法是一个测试用例。IOW,你是说NUnit应该调用相同的方法来初始化夹具和作为测试。那是可能导致抛出异常。
在 NUnit 中,意外异常不被视为失败,而是被视为错误。错误通常是您的测试有问题,而不是您正在测试的系统有问题,因此处理方式不同。特别是,只重试失败,而不会重试错误。
另请注意,NUnit 对 SpecFlow 一无所知,因此如果它是一个 specflow 异常,它将像任何其他异常一样被视为错误。
最好的办法是停止使用与测试和初始化夹具相同的方法。
我对 NUnit 重试属性有疑问 我们正在使用
NUnit 3.12.0
NUnit3TestAdapter 3.17.0
C# and Selenium
这是一个典型的特征文件
Test.feature
Scenario Template: 01 Test footer options - Homeowner
Given we set the destination to the homepage
When we select footer option "1"
Then we should see the url "tester" and title "test page"
这就是钩子
Hooks.cs
[BeforeFeature(Order = 1)]
[Test, Retry(2)]
public static void BeforeFeatureTab(FeatureContext featureContext)
{
etc
}
我们在这里捕获了故障
public void AssertUrlContains(string comparing, IWebDriver driver)
{
var currentUrl = driver.Url;
try
{
WriteToReport(Status.Pass, "Pass: URL is correct");
Assert.That(currentUrl.Contains(comparing));
}
catch (Exception ex)
{
WriteToReport(Status.Fail, "Fail error: " + ex);
Assert.That(false);
}
}
现在我认为 Assert.That(false) 会触发重试,但现在是。谁能看到我做错了什么或错过了什么感到高兴。 谢谢 凯夫
虽然你没有标记它,但我假设你正在使用 SpecFlow。虽然我对它不是很了解,但我从帮助使用 NUnit 的人那里学到了一些东西。也就是说,这就是我的想法...
BeforeFeatureAttribute
转换为 NUnit OneTimeSetUpAttribute
(以前称为 TestFixtureSetUpAttribute
,在任何测试之前调用 运行。OTOH,TestAttribute
表示方法是一个测试用例。IOW,你是说NUnit应该调用相同的方法来初始化夹具和作为测试。那是可能导致抛出异常。
在 NUnit 中,意外异常不被视为失败,而是被视为错误。错误通常是您的测试有问题,而不是您正在测试的系统有问题,因此处理方式不同。特别是,只重试失败,而不会重试错误。
另请注意,NUnit 对 SpecFlow 一无所知,因此如果它是一个 specflow 异常,它将像任何其他异常一样被视为错误。
最好的办法是停止使用与测试和初始化夹具相同的方法。