【问题标题】:Specflow - How to use FeatureContext in BeforeFeature for Parallel TestsSpecflow - 如何在 BeforeFeature 中使用 FeatureContext 进行并行测试
【发布时间】:2017-05-05 02:47:33
【问题描述】:

要并行运行测试,您不能按原样使用 FeatureContext(例如:FeatureContext.Current.FeatureInfo.Title)。 所以你必须像文档状态 http://specflow.org/documentation/Parallel-Execution/

那样注入它

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

举例来说,我有这个 Hook 在不并行运行时可以正常工作:

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

我该如何解决?

谢谢!

【问题讨论】:

    标签: specflow


    【解决方案1】:

    使用 SpecFlow https://github.com/techtalk/SpecFlow/pull/779

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

    【讨论】:

    • 谢谢!这很有帮助!
    • 嗨 Andreas,对于 scenarios 也有这个意义,即为 Before/AfterScenario 钩子注入 ScenarioContext 是否有意义?我们还能如何访问,例如ScenarioContext 的 TestError 在并行执行上下文中?附带说明:基于管道的方法不会使测试执行引擎更容易开发/维护以及使用吗?
    • @VincentSels:您已经可以通过上下文注入获得 ScenarioContext(请参阅末尾的 specflow.org/documentation/ScenarioContext)。这已经在 SpecFlow 1.9 中有效,并且可以在并行运行中使用。但是将它也作为钩子的参数是一个好主意。请在github.com/techtalk/SpecFlow 上提出问题
    猜你喜欢
    • 2016-02-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-01-19
    • 2012-10-12
    相关资源
    最近更新 更多