.net 如何覆盖ScenarioCleanup()的Specflow功能CS代码

.net 如何覆盖ScenarioCleanup()的Specflow功能CS代码,.net,specflow,.net,Specflow,是否可以编写一个新的全局方法来覆盖自动生成的specflow feature.cs文件中的ScenarioCleanup() public virtual void ScenarioCleanup() { testRunner.CollectScenarioErrors(); } 我希望ScenarioCleanup()不运行 我的代码在.Net中 我之所以需要这样做,是因为ScenarioCleanup()在从另一个项目调用方法时返回“

是否可以编写一个新的全局方法来覆盖自动生成的specflow feature.cs文件中的ScenarioCleanup()

public virtual void ScenarioCleanup()
        {
            testRunner.CollectScenarioErrors();
        }
我希望ScenarioCleanup()不运行

我的代码在.Net中

我之所以需要这样做,是因为ScenarioCleanup()在从另一个项目调用方法时返回“object not set to a instance of The object”错误。从我的步骤定义运行这个其他项目方法很好,但是当我从功能文件->步骤定义->其他项目方法运行测试时,我得到了错误

我的specflow项目位于一个大型解决方案中,其中包含许多具有大量相关依赖项的项目。我无法对这些其他开发项目进行更改


这不是答案,而是我收到的初始错误消息。即,我要覆盖场景清理的原因

Test method ApplicationUnderTest.IntegrationTests.AutomationTests.Features._000_Stage5Feature.Stage5_Atester threw exception: 
System.NullReferenceException: Object reference not set to an instance of an object.

    at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.HandleBlockSwitch(ScenarioBlock block)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.ExecuteStep(StepInstance stepInstance)
   at TechTalk.SpecFlow.Infrastructure.TestExecutionEngine.Step(StepDefinitionKeyword stepDefinitionKeyword, String keyword, String text, String multilineTextArg, Table tableArg)
   at TechTalk.SpecFlow.TestRunner.Then(String text, String multilineTextArg, Table tableArg, String keyword)
   at ApplicationUnderTest.IntegrationTests.AutomationTests.Features._000_Stage5Feature.Stage5(String role, String user, String row, String[] exampleTags) in 000_Stage5.feature: line 9
   at ApplicationUnderTest.IntegrationTests.AutomationTests.Features._000_Stage5Feature.Stage5_Atester() in 000_Stage5.feature.cs: line 0

有什么建议可以解释我为什么会收到这个错误吗?

场景清理可能是错误的原因,这似乎很不寻常。它是否可能通过清理您的一些资源触发了这些错误?也许IDisPobles或带有最终用户的对象表现不好?如果是这样的话,避免清理并不能防止它们超出范围。我同意这是不寻常的行为。返回的错误还在信息中列出ScenarioCleanup()。因此,我能够注释掉ScenarioCleanup()方法,然后运行测试,测试成功通过。但是很明显,这个注释在自动生成的faeture.cs中,因此它在项目构建后重新生成。