Search code examples
c#nunitspecflow

Skipping Feature - SpecFlow C#


I'm looking to intercept a test using the [BeforeFeature] SpecFlow Hook and ignore the entire feature file.

private static string FeatureName = FeatureContext.Current.FeatureInfo.Title;

[BeforeFeature]
public static void BeforeFeature()
{
    Console.WriteLine("Before feature");

    if (TestFilter.ShouldBeIgnored(FeatureName))
    {
        // Ignore Feature if it matches TestFilter Requirements
    }
}

Solution

  • If you are using Specflow + Nunit, you can call

    Assert.Ignore("ignore message here");
    

    This will cause the individual tests to be ignored, if their feature is ran. However, this may require you to use a BeforeScenario hook instead of a BeforeFeature hook.

    Because BeforeScenario has access to the feature info, this should not be an issue.