SpecFlowOSS / SpecFlow

#1 .NET BDD Framework. SpecFlow automates your testing & works with your existing code. Find Bugs before they happen. Behavior Driven Development helps developers, testers, and business representatives to get a better understanding of their collaboration
https://www.specflow.org/
Other
2.22k stars 751 forks source link

Teardown [AfterFeature] fails in a multi-scenario feature file #2743

Open dusloth opened 3 months ago

dusloth commented 3 months ago

SpecFlow Version

3.9.74

Which test runner are you using?

NUnit

Test Runner Version Number

4.0.1

.NET Implementation

.NET 6.0

Project Format of the SpecFlow project

Sdk-style project format

.feature.cs files are generated using

SpecFlow.Tools.MsBuild.Generation NuGet package

Test Execution Method

Visual Studio Test Explorer

SpecFlow Section in app.config or content of specflow.json

No response

Issue Description

TearDown method fails after final scenario is ran in a [BeforeFeature] and [AfterFeature] setup.

Error

TearDown failed for test fixture ConsoleApp2.Features.TestingThingFeature
TearDown : System.NullReferenceException : Object reference not set to an instance of an object.
StackTrace: --TearDown
   at ConsoleApp2.Misc.test.TearDown() in C:\Users\user\source\repos\ConsoleApp2\ConsoleApp2\Misc\test.cs:line 32
   at InvokeStub_Action`1.Invoke(Object, Span`1)
   at System.Reflection.MethodBaseInvoker.InvokeWithOneArg(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.FireEvents(HookType hookType)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.OnFeatureEnd()
   at TechTalk.SpecFlow.TestRunner.OnFeatureEnd()
   at ConsoleApp2.Features.TestingThingFeature.FeatureTearDown()
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeWithNoArgs(Object obj, BindingFlags invokeAttr)

Steps to Reproduce

Hook

 [Binding]
    internal class test
    {

        public static ThreadLocal<IWebDriver> driver = new ThreadLocal<IWebDriver>();
        //public static IWebDriver driver;

        [BeforeFeature]
        public static void SetUp()
        {
            new DriverManager().SetUpDriver(new ChromeConfig());
            driver.Value = new ChromeDriver();
        }

        [AfterFeature]
        public static void TearDown()
        {
            driver.Value.Close();
            driver.Value.Quit();
        }

    }

Feature File

Feature: TestingThing

@Thingy1
Scenario: Go to SS Fitness and click btn
    Given I navigate to SS Fitness
    And I wait for page load
    When I click the thing button
    Then I verify page changes properly

Scenario: Go to SS Fitness and click btnn1
    Given I navigate to SS Fitness
    And I wait for page load
    When I click the thing button
    Then I verify page changes properly

Link to Repro Project

No response