Visual Studio 2015 の既存の単体テスト プロジェクト (XUnit 2.0 ベース) に Specflow/Specrun を追加しました。
1 つのシナリオを実行しようとすると、同じことを 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" />
XUnitの何かが干渉している場合に備えて、App.configに次を追加しようとしましたが、役に立ちませんでした:
<add key="xunit.maxParallelThreads" value="1"/>
<add key="xunit.parallelizeTestCollections" value="false"/>
すでに 1 回成功しているのに、なぜテストが 4 回実行されるのかわかりません。何が問題で、どのように対処すればよいでしょうか? これは、ブラウザを呼び出すテストでのみ発生することに注意してください。他の人にとっては、それはうまくいくようです。
PS: これは Specflow/Specrun を既存の単体テスト プロジェクトに追加した後にのみ発生します。specflow がインストールされた別のソリューションで複数のプロジェクトをサイドに作成しましたが、それらは問題なく機能しました。