【问题标题】:Cucumber not recognizing tags黄瓜不识别标签
【发布时间】:2022-07-21 18:38:25
【问题描述】:

我有一个奇怪的问题,Cucumber 无法识别标签。我想从执行中排除一个场景,但它仍在执行中。我使用的是黄瓜 6.10.2 版本(io.cucumber)。

所以场景是:

@tag1
  Scenario Outline: Attempt to Create Contract                
    Given I delete all test data for <some collection name>
    And I delete all test data for <other collection name>

我的跑步者班级是:

import io.cucumber.junit.Cucumber;
import io.cucumber.junit.CucumberOptions;
import org.junit.runner.RunWith;

        @RunWith(Cucumber.class)
        @CucumberOptions(
                features = "src/test/java/resources"
                , glue = {"stepDefinitions"}
                , plugin = {"pretty", "html:target/cucumber-reports",
                "html:target/cucumber-report/cucumber.html",
                "html:target/cucumber-report.html",
                "json:target/cucumber.json"}
                , tags = "not @tag1"
    
    )
    
    public class RuneCukeTest {
    }

我还尝试了不同的标签语法,例如:

tags = ~"@tag1"
tags = "~@tag1"

但没有一个工作。 (即使我尝试只运行这个标签)。 它不允许我这样输入,可能是因为版本:

tags = {"@tag1"}

我在“标签”文档下找到的是:

  String tags() default "";

上面的例子“@smoke 而不是@fast”

注意事项:

我使用的 .feature 文件很少,我只想执行一个并从中跳过 1 个场景。我正在尝试两者 - 使用 @CucumberOptions 从运行器类执行它,并通过右键单击 .feature 文件本身。没有任何效果...

【问题讨论】:

  • 你试过tags = "{@feature not @tag1)"吗? (其中@feature 是功能文件最顶部使用的标签)。您也可以尝试使用波浪号。
  • 是的,它还没有工作:/

标签: cucumber cucumber-java


【解决方案1】:

好吧,今天我找到了部分解决方案。 我添加了 2 个标签 - 一个要跳过,一个要运行(不同的场景)。

tags = "not @Opportunities" + "@Testing123"

它在终端上运行,具有以下功能:

mvn clean
mvn test "-Dcucumber.filter.tags= not @Opportunities and @Testing123"

我已经设法使它仅在启动运行器类后才起作用,但仅在终端执行完成后才起作用。我尝试使用相同的算法再次运行它,但没有成功。

【讨论】:

  • 这很奇怪。
  • 是的,我还在寻找一个正常的解决方案
【解决方案2】:

我很困惑为什么我的测试没有被接受并发现一些有趣的东西。

我正在填充以下环境变量(我正在使用 gitlab 管道)

CUCUMBER_FILTER_TAGS: "@SmokeTest and @integration not @ignore"

这又被传递给gradle任务

-Dcucumber.filter.tags= not @SmokeTest and @integration not @ignore

现在,当我正在编写新的管道时,将会有一些使用 @SmokeTest 的测试和一些使用 @integration 的测试

但是在运行此作业时,我的功能文件没有使用 @integration 进行任何测试

现在有趣的部分来了,如果您使用 and 子句将不存在的标签放在过滤条件中,它就不起作用。 @ignore 是 cucumber 内部的,因此如果您没有标记有 @ignore 的测试,则不会导致问题。

所以它没有选择任何要运行的测试。

我没有尝试过,但我认为 or 子句可能对不存在的标签有效

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2014-01-10
    • 2021-06-09
    • 2016-06-04
    • 1970-01-01
    • 1970-01-01
    • 2018-09-23
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多