如何排除黄瓜标签

时间:2015-02-09 11:42:48

标签: java scala cucumber cucumber-junit

我有很多带有各种黄瓜标签的IT案例。在我的主要跑步者课程中,我想排除所有具有@one或@two的场景。因此,下面是我尝试的选项选项1

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

选项2

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

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

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

4 个答案:

答案 0 :(得分:12)

我想我弄清楚它是如何运作的。

@Cucumber.Options(tags = {"~@one, ~@two"}) - 这意味着如果' @one不在那里' 如果' @two不存在'然后执行方案

因此,执行以下功能中的所有方案。因为,第一个场景标有@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的场景才被执行。

答案 1 :(得分:1)

是否有可能它不喜欢数组,也许尝试:

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

答案 2 :(得分:0)

通常,标签后面有以下逻辑:

AND逻辑是这样的:

tags = {"@Tag1", "@Tag2"} //both tags must be present or:
tags = {"~@Tag1", "~@Tag2"} // both tags must not be present, 
//if only one is the stuff will be executed!

OR逻辑是这样的:

tags = {"@Tag1, @Tag2"} //one of these Tags must be present or:
tags = {"~@Tag1, ~@Tag2"} //one of these Tags must not be present, the Rest will be executed!

但是我发现,黄瓜很快将在标签中支持“或”-运算符并替换逗号+””-STUFF ..,因此更容易表达差异。真是像这样:

tags = {"@Tag1 or @Tag2"}

系统发出的原始消息是:

Support for '@tag1,@tag2' will be removed from the next release of Cucumber-JVM. Please use '@tag or @tag2' instead

希望这对将来也有帮助。 :)

答案 3 :(得分:0)

如何排除/忽略一个标签

(这个答案可以帮助其他只想忽略一个标签的用户)

终端:

mvn clean test -Dcucumber.filter.tags="not @one"

Junit:

@CucumberOptions(tags = "not @one")