How to run specflow feature files in parallel?

2019-07-19 18:03发布

问题:

I am using specflow with NUnit on Saucelabs. I need to run features files in parallel . But I read somewhere that you cannot run in parallel if you are using ScenarioContext/FeatureContext which I am currently using in almost every test scenario. Is it true ? If true , what alternative can I use for multi threading. Please note that there is no dependency between the features or between the testcases in features. Can anyone provide a code snippet to help me implement parallel execution. Thanks for the help in advance.

[If not feature files in parallel , please do guide in running test scenarios within a feature file in parallel]

回答1:

If you want to make all your tests within one project run in serial add the following to the project's AssemblyInfo class:

[assembly: CollectionBehavior(DisableTestParallelization = true)]


回答2:

About ScenarioContext/FeatureContext:
If you use the Current- Properties you can not access these when you are running in parallel.
But you can get to the Contexts via Context Injection (http://www.specflow.org/documentation/ScenarioContext/, at the end).

About running in parallel:
Have a look for it in the documentation here: http://www.specflow.org/documentation/parallel-execution/
There is also a description about the *Context.Current handling.