Java 如何排除黄瓜标签

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/28408962/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 06:11:17  来源:igfitidea点击:

How to exclude cucumber tags

javascalacucumbercucumber-junit

提问by JavaMan

I have a bunch of IT cases with various cucumber tags. In my main runner class I want to exclude all the scenarios which have either @one or @two. So, below are the options I tried Option 1

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

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

or option 2

选项 2

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

When I tried with option one, test cases tagged with @two started executing while with second option it did not. As per cucumber documentation an OR will be maintained when tags are mentioned as "@One,@Two". If this is the case why doesn't exclude work the same way i.e. the first option?

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

Update: This piece of code is written in scala.

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

采纳答案by Eswar

I think I figured out how it works.

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

@Cucumber.Options(tags = {"~@one, ~@two"})- This translates to if '@one is not there' ORif '@two is not there' then execute the scenario

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

So all the scenarios in the below feature are executed. Because, the first scenario has tag @one but not @two. Similarly Second scenario has tag @two but not @one. Third Scenario has neither @one nor @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

To test my understanding, I updated the feature file as below. With this change, all scenarios without tags @one or @two were executed. i.e @one @three, @two @three and @three.

为了测试我的理解,我更新了功能文件如下。通过此更改,所有没有标签 @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

Now if we do an AND operation: @Cucumber.Options(tags = {"~@one", "~@two"})- this means execute a scenario only when BOTH@one and @two are not there. Even if one of the tag is there then it will not be executed. So as expected, only scenario with @three got executed.

现在,如果我们做与运算: @Cucumber.Options(tags = {"~@one", "~@two"})-这意味着执行情况,只有当BOTH@One和@two不存在。即使其中一个标签存在,它也不会被执行。所以正如预期的那样,只有@three 的场景被执行了。

回答by jmccure

Is it possible it doesn't like the Array, maybe try:

有没有可能它不喜欢数组,也许试试:

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

回答by slowlert

in general there is the folowing logic behind the tagging:

一般来说,标签背后有以下逻辑:

AND logic is like this:

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 logic is like this:

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!

But i found out, that cucumber soon will support the "or"-Operator in tagging and replace the comma+""-STUFF.., so it is easier to express the differences. It is goind to be like:

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

tags = {"@Tag1 or @Tag2"}

Original message from system is:

来自系统的原始消息是:

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

Hope this can help in future, too. :)

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