1

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 がインストールされた別のソリューションで複数のプロジェクトをサイドに作成しましたが、それらは問題なく機能しました。

4

1 に答える 1

3

SpecRun は SpecFlow に特化した TestRunner です。したがって、XUnit Runner を置き換えます。

失敗したテストの再試行は、実行セクションの retryCount 構成で制御されます。ここで SRProfile- ドキュメントを参照してください: http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/

ScenarioContext.Current エラーへ: すべての *.feature.cs ファイルを再生成しましたか? SpecFlow 2.0 では、生成されたコードにいくつかの変更があったため、再生成する必要があります。

于 2016-02-17T08:37:08.150 に答える