Specflow Hooks - 为什么它们需要是静态的?

问题描述 投票:0回答:1

我了解 C# Specflow 中挂钩的实用性,但为什么 BeforeScenario / AfterScenario 和 BeforeFeature / AfterFeature 必须是静态的?

c# hook specflow
1个回答
0
投票

查看 SpecFlow 的源代码,它看起来不像 Hooks 是静态类:

public abstract class HookAttribute : Attribute
{
    // [...]

    internal HookAttribute(HookType bindingEvent, string[] tags)
    {
        // [...]
    }
}

// [...]

public class BeforeScenarioAttribute : HookAttribute
{
    public BeforeScenarioAttribute(params string[] tags) : base(HookType.BeforeScenario, tags) { }
}

// [...]

public class BeforeFeatureAttribute : HookAttribute
{
    public BeforeFeatureAttribute(params string[] tags) : base(HookType.BeforeFeature, tags) { }
}

你有一个具体的例子来说明你的意思吗?

© www.soinside.com 2019 - 2024. All rights reserved.