我已将 Specflow/Specrun 添加到 Visual Studio 2015 中的现有单元测试项目(基于 XUnit 2.0)。
当我尝试执行单个场景时,它似乎尝试执行相同的事情 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.maxParallelThreads" value="1"/>
<add key="xunit.parallelizeTestCollections" value="false"/>
我不确定为什么测试会执行 4 次,而它已经成功了一次。可能是什么问题以及如何解决?请注意,这只发生在调用浏览器的测试中。对于其他人来说,它似乎工作得很好。
PS:这仅在将 Specflow/Specrun 添加到现有单元测试项目后才会发生。我已经在安装了 specflow 的单独解决方案中创建了多个项目,它们工作得很好。