Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vue.js/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 是否可以根据结果再次运行相同的specflow测试?_C#_Testing_Specflow - Fatal编程技术网

C# 是否可以根据结果再次运行相同的specflow测试?

C# 是否可以根据结果再次运行相同的specflow测试?,c#,testing,specflow,C#,Testing,Specflow,我正在使用Specflow、Visual studio 2015和Nunit。如果一个测试再次运行失败,我需要。我有 [AfterScenario] public void AfterScenario1() { if (Test Failed and the counter is 1) { StartTheLastTestOnceAgain(); } } 如何再次启动上一个测试?在NUnit中,有RetryAttribute()用于该测试。看起来Spe

我正在使用Specflow、Visual studio 2015和Nunit。如果一个测试再次运行失败,我需要。我有

[AfterScenario]
public void AfterScenario1()
{
    if (Test Failed  and the counter is 1)
    {
        StartTheLastTestOnceAgain();
    }
}

如何再次启动上一个测试?

在NUnit中,有RetryAttribute()用于该测试。看起来SpecFlow.Retry插件正在使用它()。这个插件是一个第三方插件,我还没有使用它。因此,不能保证这是你想要的

作为替代方案,您可以使用SpecFlow+Runner()。此专用运行程序可以选择重新运行失败的测试。(-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
    }
}

在VisualStudio中运行测试时,可以筛选失败的测试并再次运行它们。如果您想更加自动化,您可能需要查看构建服务器,例如TFS或TeamCity。这些测试有可能在您的测试中有更多的逻辑来运行它们两次。在一个测试中包含更多的代码以再次运行它们可能有一个缺点,因为测试会发生变化并变得更复杂。这不是我需要的。有些测试可能会因为网络问题而失败,这就是为什么我想重新运行那些失败的测试。最后,我将发送一份报告,这就是为什么我需要它。在我的案例中,我有2000多个测试,只有少数地方有Assert.IsTrue或Assert.equals。不会抛出Assert.IsTrue异常吗?if是如何执行的?我已经添加了Specflow。请重试,但在安装之后,很可能有什么东西被卸载了,所以我不得不恢复。我将尝试使用NUnit Retry我无法使用SpecFlow重新运行测试。请重试