是否可以根据结果再次 运行 相同的 specflow 测试?
Is it possible to run same specflow test again based on outcome?
我正在使用 Specflow、Visual studio 2015 和 Nunit。如果测试失败,我需要再次 运行 它。我有
[AfterScenario]
public void AfterScenario1()
{
if (Test Failed and the counter is 1)
{
StartTheLastTestOnceAgain();
}
}
如何重新开始上次的测试?
在 NUnit 中有 RetryAttribute (https://github.com/nunit/docs/wiki/Retry-Attribute) for that. It looks like that the SpecFlow.Retry plugin is using that (https://www.nuget.org/packages/SpecFlow.Retry/)。这个插件是一个 3rd 方插件,我还没有使用它。所以不能保证这会如你所愿。
作为替代方案,您可以使用 SpecFlow+Runner(http://www.specflow.org/plus/). This specialized runner has the option to rerun your failed test. (http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/#Execution - retryFor/retryCount 配置值)。
完全披露:我是 SpecFlow 和 SpecFlow+ 的开发者之一。
您总是可以在断言步骤中捕获失败,然后重试您测试的内容。类似于:
[Given(@"I'm on the homepage")]
public void GivenImOnTheHomepage()
{
go to homepage...
}
[When(@"When I click some button")]
public void WhenIClickSomeButton()
{
click button...
}
[Then(@"Something Special Happens")]
public void ThenSomethingSpecialHappens()
{
var theRightThingHappened = someWayToTellTheRightThingHappened();
var result = Assert.IsTrue(theRightThingHappened);
if(!result)
{
thenTrySomeStepsAgainHere and recheck result using another assert
}
}
我正在使用 Specflow、Visual studio 2015 和 Nunit。如果测试失败,我需要再次 运行 它。我有
[AfterScenario]
public void AfterScenario1()
{
if (Test Failed and the counter is 1)
{
StartTheLastTestOnceAgain();
}
}
如何重新开始上次的测试?
在 NUnit 中有 RetryAttribute (https://github.com/nunit/docs/wiki/Retry-Attribute) for that. It looks like that the SpecFlow.Retry plugin is using that (https://www.nuget.org/packages/SpecFlow.Retry/)。这个插件是一个 3rd 方插件,我还没有使用它。所以不能保证这会如你所愿。
作为替代方案,您可以使用 SpecFlow+Runner(http://www.specflow.org/plus/). This specialized runner has the option to rerun your failed test. (http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/#Execution - retryFor/retryCount 配置值)。
完全披露:我是 SpecFlow 和 SpecFlow+ 的开发者之一。
您总是可以在断言步骤中捕获失败,然后重试您测试的内容。类似于:
[Given(@"I'm on the homepage")]
public void GivenImOnTheHomepage()
{
go to homepage...
}
[When(@"When I click some button")]
public void WhenIClickSomeButton()
{
click button...
}
[Then(@"Something Special Happens")]
public void ThenSomethingSpecialHappens()
{
var theRightThingHappened = someWayToTellTheRightThingHappened();
var result = Assert.IsTrue(theRightThingHappened);
if(!result)
{
thenTrySomeStepsAgainHere and recheck result using another assert
}
}