Specflow - 如何在 BeforeFeature 中使用 FeatureContext 进行并行测试

Specflow - How to use FeatureContext in BeforeFeature for Parallel Tests

到 运行 并行测试,您不能按原样使用 FeatureContext(例如:FeatureContext.Current.FeatureInfo.Title)。 所以你必须像文档说明的那样注入它 http://specflow.org/documentation/Parallel-Execution/

但是,如果我在 [BeforeFeature] 挂钩中使用 FeatureContext,它必须是静态方法,根据:https://github.com/techtalk/SpecFlow/wiki/Hooks

为了举例说明,我有这个 Hook 在不并行 运行ning 时工作正常:

[BeforeFeature]
internal static void BeforeFeature()
{
// Some code here
string title = FeatureContext.Current.FeatureInfo.Title;
// More code here
}

我该如何解决?

谢谢!

SpecFlow <= 2.1 这是不可能的。 在 SpecFlow 2.2 中,我们添加了获取 FeatureContext 作为参数的功能。在此处查看此 PR https://github.com/techtalk/SpecFlow/pull/779

现在要使用它,您必须使用来自 CI- 提要的版本。计划在下周进行预发布。