ThreadSafe scenario/feature context

蹲街弑〆低调 提交于 2020-07-22 03:48:04

问题


I am having trouble adding the ability to call the feature and scenario contexts when running the framework in parallel.

I have looked over

http://specflow.org/documentation/Parallel-Execution/

but I am still having trouble understanding how to actually add this to the framework.

Does anyone have an example of this working in practice?

I am trying to create a report using

ParentNode = Extent.CreateTest(FeatureContext.Current.FeatureInfo.Title);

but I cant call this when running in parallel, any help on getting this thread safe will be extremely welcome


回答1:


In simple terms you cannot call FeatureContext.Current or ScenarioContext.Current in parallel.

instead ask for an instance of either FeatureContext or ScenarioContext in the constructor of the steps class that you want to use it in, and Specflows DI container will give you the current one for the currently executing test, and you can then store that as a field in your class and use that field safely.



来源:https://stackoverflow.com/questions/48586809/threadsafe-scenario-feature-context

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!