可以跳过/忽略没有 Assert.Assume(..) 的 Cucumber 测试用例

It is possible to skip / ignore Cucumber test case without Assert.Assume(..)

我有包含多个测试用例(使用“示例”)的 Cucumber .feature 文件。
在某些情况下,我想跳过一些测试用例,运行 只跳过其中的几个。

注: 用户应该能够select动态
跳过哪个测试用例 例如,他可以决定先 运行 跳过测试用例 1,下次跳过测试用例 2。

Examples:
  | SERIAL_NO | ID                |
  | 1         | Create-Customer A |
  | 2         | Create-Customer B |
  | 3         | Create-Customer C |

我设法使用

做到了
Assume.assumeTrue(...)

唯一的问题是 - 代码抛出异常,我希望保持日志清晰

有什么选项可以避免打印异常,而忽略测试用例吗? 或者通过其他解决方案跳过它?

谢谢

我会为您想要跳过测试的每个场景拆分您的示例并使用 @todo 标记,如下所示:

   Scenario Outline: [test-scenario-001] Send a new form with request type  
   Given I preload the from using "request"
   And I select the 'Submit' button
   Then the response message "hello" is returned
   Examples:
    | request |
    | POST    |
   @todo
   Examples:
    | request | 
    | GET     |
    | PUT     |
    | DELETE  |

然后运行第一个Example的场景,标注标签不要运行作为特征的一部分:

-Dcucumber.options="--tags ~@todo"

对运行所有Example场景,不使用标签

最后我找到了一个简单的解决方案,通过使用我提到的相同方法 Assert.assume(...),只需要清除异常堆栈跟踪,和 re-throw 它。

在下面的代码中你可以看到实际的变化只是我添加了 catch 块:

try
{
    Assume.assumeTrue("Some Condition...");
}
catch (AssumptionViolatedException e)
{
    // clearing stack trace, so it will keep logs clear, just print the name of exception
    e.setStackTrace(new StackTraceElement[] {});
    throw e;
}

现在不将异常堆栈跟踪打印到日志中,因此日志保持干净,我只看到了这个:

org.junit.AssumptionViolatedException: got: <false>, expected: is <true>

这对我来说已经足够了。