2016-02-17 43 views
1

我已经在Visual Studio 2015中将Specflow/Specrun添加到现有的单元测试项目(基于XUnit 2.0)。为什么Specflow试图多次执行相同的场景?

当我尝试执行单个场景时,它似乎尝试并执行相同的操作4次。这里是控制台输出:

Scenario: Add true/false question in AddTrueFalseQuestion -> Succeeded on thread #0 
Scenario: Add true/false question in AddTrueFalseQuestion -> Failed on thread #0 
    [ERROR] Trace listener failed. -> The ScenarioContext.Current static accessor cannot be used in multi-threaded execution. Try injecting the scenario context to the binding class. See http://go.specflow.org/doc-multithreaded for details. 
Scenario: Add true/false question in AddTrueFalseQuestion -> Failed on thread #0 
    [ERROR] Trace listener failed. -> The ScenarioContext.Current static accessor cannot be used in multi-threaded execution. Try injecting the scenario context to the binding class. See http://go.specflow.org/doc-multithreaded for details. 
Scenario: Add true/false question in AddTrueFalseQuestion -> Failed on thread #0 
    [ERROR] Trace listener failed. -> The ScenarioContext.Current static accessor cannot be used in multi-threaded execution. Try injecting the scenario context to the binding class. See http://go.specflow.org/doc-multithreaded for details. 
Result: 1 failed 
    Total: 2 (test executions: 4) 
    Succeeded: 1 
    Ignored: 0 
    Pending: 0 
    Skipped: 0 
    Failed: 1 

事情我已经尝试:

  • 我已经搜查,以验证项目中的任何文件必须ScenarioContext.Current基准按上述错误但没有发现任何东西

  • specflow的default.sprofile测试配置文件具有以下配置,但不确定它是否被服从:

    < Execution stopAfterFailures="3" testThreadCount="1" testSchedulingMode="Sequential" />

  • 我甚至尝试加入以下的App.config的情况下,如果东西的xUnit被干扰,但无济于事:

    ​​

    <add key="xunit.parallelizeTestCollections" value="false"/>

我不确定为什么测试会执行4次,当它已经成功一次。可能是什么问题以及如何解决?请注意,这只发生在调用浏览器的测试中。对于其他人来说,它似乎工作得很好。 PS:只有在将Specflow/Specrun添加到现有的单元测试项目后才会发生这种情况。我在一侧创建了多个项目,它们安装了specflow并且工作得很好。

回答

3

SpecRun是专门为SpecFlow设计的TestRunner。所以它取代了XUnit Runner。

失败测试的重试次数由执行部分的retryCount配置控制。请参阅SRProfile-文档:http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/

到ScenarioContext.Current错误:是否重新生成所有* .feature.cs文件?使用SpecFlow 2.0时,生成的代码发生了一些变化,因此必须重新生成。

+0

我设置了'retryFor =“None”'。但是,测试并没有真正失败。它总是成功,它似乎仍然重试,然后由于某些原因而导致这些跟踪侦听器异常失败。对于* .feature.cs文件,我刚刚删除它们并让它们自动生成。 – PhD

相关问题