java - 如何排除 cucumber 标签

标签 java scala cucumber cucumber-junit

我有一堆带有各种 cucumber 标签的 IT 案例。在我的主要运行者类(class)中,我想排除所有具有@one 或@two 的场景。所以,下面是我尝试过的选项 Option 1

@CucumberOptions(tags=Array("~@one,~@two"), .....)

选项2

@CucumberOptions(tags=Array("~@one","~@two").....

当我尝试使用选项一时,标有@two 的测试用例开始执行,而使用第二个选项则没有。 根据 cucumber 文档,当标记被提及为 "@One,@Two" 时,将维护一个 OR。如果是这种情况,为什么不以相同的方式排除工作,即第一个选项?

更新:这段代码是用scala写的。

最佳答案

我想我知道它是如何工作的。

@Cucumber.Options(tags = {"~@one, ~@two"}) - 这转化为如果“@one 不存在”如果'@two is not there' 然后执行场景

因此以下功能中的所有场景都已执行。因为,第一个场景有标签@one 但没有@two。 同样,第二个场景有标签@two 但没有@one。 第三种情况既没有@one 也没有@two

Feature:
  @one
  Scenario: Tagged one
    Given this is the first step

  @two
  Scenario: Tagged two
    Given this is the first step

  @three
  Scenario: Tagged three
    Given this is the first step

为了测试我的理解,我更新了功能文件如下。通过此更改,将执行所有没有标记@one 或@two 的场景。即@one @three、@two @three 和@three。

Feature:
  @one @two
  Scenario: Tagged one
    Given this is the first step

  @two @one
  Scenario: Tagged two and one
    Given this is the first step

  @one @three
  Scenario: Tagged one and three
    Given this is the first step

  @two @three
  Scenario: Tagged two and three
    Given this is the first step

  @one @two @three
  Scenario: Tagged one two and three
    Given this is the first step

  @three
  Scenario: Tagged three
    Given this is the first step

现在如果我们做一个 AND 操作: @Cucumber.Options(tags = {"~@one", "~@two"}) - 这意味着只有当 BOTH @one 和 @two 是时才执行场景不在那里。即使其中一个标签存在,它也不会被执行。 因此,正如预期的那样,只执行了带有@three 的场景。

关于java - 如何排除 cucumber 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28408962/

相关文章:

android - 设置和使用 Gherkin Android Studio

java - 为什么 java.net.URI 不解析权限部分?

java - 如何让 OkHttpClient 遵守 REST API 速率限制?

java - 为什么他们在从输入流读取时使用 "while"语句?

scala - 玩2.4 表单字段值绑定(bind)到类型java.time.LocalDate

javascript - 如何在 Protractor Cucumber 框架中使用断点进行调试

java - 删除最后一个元素后的空格 ""

scala - 连接类型是否定义为 Apache Spark 中某处可访问的常量?

scala - Scala 中的逆变和协变

ruby-on-rails - rails 上的 ruby 。 bundler 。 cucumber 。 rake 中止!命令失败,状态为 (1)