【发布时间】:2021-10-26 12:15:28
【问题描述】:
我希望能够避免执行 specflow 场景,或者在第一步退出,具体取决于外部配置。这可能吗?
喜欢 背景: 假设我们有一个满足的前提条件
前提条件失败,场景停止且不返回错误
【问题讨论】:
我希望能够避免执行 specflow 场景,或者在第一步退出,具体取决于外部配置。这可能吗?
喜欢 背景: 假设我们有一个满足的前提条件
前提条件失败,场景停止且不返回错误
【问题讨论】:
IUnitTestRuntimeProvider 接口应该被注入 https://docs.specflow.org/projects/specflow/en/latest/Execution/SkippingScenarios.html
然而,我又遇到了这个界面无法解析的事实 https://github.com/SpecFlowOSS/SpecFlow/issues/2076 在带有 Visual Studio 2019 的 .Net 5、XUnit 项目中,此解决方案对我不起作用
【讨论】:
如果某个步骤未引发异常,则该步骤通过。您可以将该特定步骤重构为私有方法,然后简单地将方法调用包装在 if 语句中的 try-catch 中:
[Given(@"we have a satisfied precondition")]
public void GivenWeHaveASatisfiedPrecondition()
{
if (/* check your external config here */)
{
try
{
PerformPrecondition();
}
catch (Exception ex)
{
Console.WriteLine("Step failed, but continuing scenario." + Environment.NewLine + Environment.NewLine + ex);
}
}
else
{
// Failure in this step should fail the scenario.
PerformPrecondition();
}
}
private void PerformPrecondition()
{
// Your step logic goes here
}
您尚未指定外部配置的位置,但有上千种方法可以做到这一点。
【讨论】: