Cucumber with JUnit 5:未找到功能,测试为';不执行

Cucumber with JUnit 5:未找到功能,测试为';不执行,cucumber,junit5,Cucumber,Junit5,我在JUnit4中使用Cucumber已经有一段时间了,但是现在我第一次需要在JUnit5中使用Cucumber,它似乎不起作用。我有以下依赖项: ... <dependency> <groupId>org.junit.platform</groupId> <artifactId>junit-platform-launcher</artifactId> <scope>tes

我在JUnit4中使用Cucumber已经有一段时间了,但是现在我第一次需要在JUnit5中使用Cucumber,它似乎不起作用。我有以下依赖项:

    ...
    <dependency>
      <groupId>org.junit.platform</groupId>
      <artifactId>junit-platform-launcher</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.jupiter</groupId>
      <artifactId>junit-jupiter-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.junit.vintage</groupId>
      <artifactId>junit-vintage-engine</artifactId>
      <scope>test</scope>
    </dependency>
    ...
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit-platform-engine</artifactId>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-picocontainer</artifactId>
      <scope>test</scope>
    </dependency>
    ...
在这里,我使用@Tag注释替换JUnit4@Category,以便根据上面的failsafe maven插件中配置的元素有选择地执行测试

fetaures文件位于src/main/test/resources/features/it中,其名称为customers.features

最后但并非最不重要的一点是,以下是steps类:

@Tag("profileServer")
public class CustomersCucumberSteps
{
  ...
}
运行验证目标将显示以下输出: ┌─────────────────────────────────────────────────────────────────────────────┐ │ 与您的团队分享您的黄瓜报告,网址为│ │ 使用以下选项之一激活发布:│ │ │ │ src/test/resources/cucumber.properties:cucumber.publish.enabled=true│ │ 环境变量:CUCUMBER\u PUBLISH\u ENABLED=true│ │ JUnit:@CucumberOptions(publish=true)│ │ │ │ 更多信息请访问│ │ │ │ 要禁用此消息,请将cumber.publish.quiet=true添加到│ │ src/test/resources/cucumber.properties│ └─────────────────────────────────────────────────────────────────────────────┘

但是简单地跳过测试执行,就好像没有任何测试一样。以前,对于JUnit4,我使用@CucumberOptions来设置特性位置。但是JUnit5不再支持这种注释,我也找不到其他注释。看来它应该被发现

我看过几篇文章提到功能文件可能在failsafe或surefire maven插件中配置为:

...
<options>
  <configurationParameters>
    ...
  </configueationParameters>
</options>
...
。。。
...
...
但是这种语法似乎不受支持,而且,无论如何,我没有找到任何可以用来配置步骤位置的参数

有人能告诉我这一点,并提供一个简单的例子吗

非常感谢

西摩

Maven Surefire和Gradle还不支持发现非基于类的测试(参见:Gradle/#4773,Surefire-1724)

作为一种解决方法,您可以使用
@cumber
注释。Cucumber将扫描带有
@Cucumber
注释的类的包以查找功能文件

因此,如果runner类是
src/test/java/com/example/RunCucumberIT
,那么功能文件应该在
src/test/resources/com/example

Maven Surefire和Gradle还不支持发现非基于类的测试(参见:Gradle/#4773,Surefire-1724)

作为一种解决方法,您可以使用
@cumber
注释。Cucumber将扫描带有
@Cucumber
注释的类的包以查找功能文件


因此,如果runner类是
src/test/java/com/example/RunCucumberIT
,那么功能文件应该位于
src/test/resources/com/example
,我在回答我自己的问题。事实上,在我的例子中使用的Cucumber 6.7.0似乎无法正确解释JUnit 5“@Tag”注释。在上面介绍的当前测试用例中,注释掉故障保护插件配置中的“groups”语句(用于过滤测试执行)的行为符合预期,即执行所有测试。保持此语句未注释,并且无论“@Tag”注释定义了什么,都将跳过所有测试


但是,JUnit4“@Category”注释按预期工作,即过滤正常。因此,为了基于maven概要文件过滤Cucumber测试的执行,只有JUnit4风格可以工作。

我在回答我自己的问题。事实上,在我的例子中使用的Cucumber 6.7.0似乎无法正确解释JUnit 5“@Tag”注释。在上面介绍的当前测试用例中,注释掉故障保护插件配置中的“groups”语句(用于过滤测试执行)的行为符合预期,即执行所有测试。保持此语句未注释,并且无论“@Tag”注释定义了什么,都将跳过所有测试


但是,JUnit4“@Category”注释按预期工作,即过滤正常。因此,为了基于maven概要文件过滤Cucumber测试的执行,只有JUnit 4风格可以工作。

不确定我该怎么做,因为附加文档链接从来都不是一个恰当的答案。因此,如果你建议使用@cumber注释,那么你可能想再次阅读你正在回复的帖子。另外,如果您建议步骤和IT类应该在同一个包中,那么它们已经在同一个包中了。我指的是
.feature
文件,而不是步骤定义。Cucumber将扫描带有
@Cucumber
注释的类的包以查找功能文件。是的,我也是。对不起,我刚才说的是功能。它们位于资源文件夹中的一个目录中,与包含runner和steps类的Java包具有相同的路径。所有的测试都会被忽略,就好像它们不存在一样。它与JUnit4和@CucumberOptions.Ah的预期一样工作。通常情况下,人们从
@Tag("profileServer")
public class CustomersCucumberSteps
{
  ...
}
...
<options>
  <configurationParameters>
    ...
  </configueationParameters>
</options>
...