如何使用TechTalk.SpecFlow和C#以编程方式忽略一些验收测试?
我有几个功能文件和一些场景。我需要忽略几个场景或功能,这些场景或功能根据某些条件标记为一些如何使用TechTalk.SpecFlow和C#以编程方式忽略一些验收测试?,c#,specflow,acceptance-testing,C#,Specflow,Acceptance Testing,我有几个功能文件和一些场景。我需要忽略几个场景或功能,这些场景或功能根据某些条件标记为一些@tag。我已经读过了,但没有发现对我的解决方案有用的东西。我想用像这样的东西 [BeforeScenario("sometag")] public static void BeforeScenario() { if(IgnoreTests) { // This is the hot spot Scenario.DoSomethingToIgnoreScenari
@tag
。我已经读过了,但没有发现对我的解决方案有用的东西。我想用像这样的东西
[BeforeScenario("sometag")]
public static void BeforeScenario()
{
if(IgnoreTests)
{
// This is the hot spot
Scenario.DoSomethingToIgnoreScenarioIfConditionButRunScenarioIfConditionFalse();
}
}
我还尝试动态添加或删除标记
[BeforeScenario("sometag")]
public static void BeforeScenario()
{
if(IgnoreTests)
{
ScenarioContext.Current.ScenarioInfo.Tags.ToList().Add("ignore");
}
}
但它不起作用。也许还有其他方法可以动态添加或删除标记?或者
ScenarioContext
类中的某些方法将忽略当前场景?您至少有3个选项:
missingorpendingstepsoutcom=“ignore”
将挂起的步骤视为ignore,然后您可以编写:
if(IgnoreTests)
{
ScenarioContext.Current.Pending();
}
这可能不是您想要的,这取决于您对待定步骤的要求IUnitTestRuntimeProvider
接口:
if (IgnoreTests)
{
var unitTestRuntimeProvider = (IUnitTestRuntimeProvider)
ScenarioContext.Current
.GetBindingInstance((typeof (IUnitTestRuntimeProvider)));
unitTestRuntimeProvider.TestIgnore("ignored");
}
即使您更改了UnitTestProvider,这也会起作用,但不能保证这个API将来不会崩溃if (IgnoreTests)
{
var unitTestRuntimeProvider = (IUnitTestRuntimeProvider)
ScenarioContext.Current
.GetBindingInstance((typeof (IUnitTestRuntimeProvider)));
unitTestRuntimeProvider.TestIgnore("ignored");
}