Reputation: 11334
I've added Specflow/Specrun to an existing Unit Testing project (based on XUnit 2.0) in Visual Studio 2015.
When I try to execute a single scenario it seems to try and execute the same thing 4 times. Here's the console output:
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
Things I've tried:
I've searched to verify if any file in the project has a reference to ScenarioContext.Current
, as per the above error but haven't found anything
The default.sprofile testing profile of specflow has the following configuration but not sure if it's being obeyed:
< Execution stopAfterFailures="3" testThreadCount="1" testSchedulingMode="Sequential" />
I even tried adding the following to App.config in case if something in XUnit was interfering, but to no avail:
<add key="xunit.maxParallelThreads" value="1"/>
<add key="xunit.parallelizeTestCollections" value="false"/>
I'm not sure why the test would be executing 4 times, when it already succeeded once. What could be the issue and how to address it? Note that this is only happening for tests that call the browser. For others, it seems to work just fine.
PS: This is only happening after adding Specflow/Specrun to an existing unit testing project. I've created multiple projects on the side in separate solutions that had specflow installed and they worked just fine.
Upvotes: 1
Views: 2456
Reputation: 5825
SpecRun is a TestRunner specialized for SpecFlow. So it replaces the XUnit Runner.
The retries of failing tests is controlled with the retryCount config of the Execution section. See the SRProfile- Documentation here: http://www.specflow.org/plus/documentation/SpecFlowPlus-Runner-Profiles/
To the ScenarioContext.Current errors: Did you regenerate all your *.feature.cs files? With SpecFlow 2.0 there were some changes of the generated code and so they have to be regenerated.
Upvotes: 3