PhD
PhD

Reputation: 11334

Why does Specflow try to execute the same scenario multiple times?

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'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

Answers (1)

Andreas Willich
Andreas Willich

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

Related Questions