带有 junit5 和 java8 的黄瓜

Cucumber with junit5 and java8

我正在尝试为用 java11 编写的 spring 引导应用程序创建 BDD 测试,并使用 junit5 进行测试。

我正在尝试 6.9.1 版本的黄瓜,我对这部分的依赖是:

<dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-java8</artifactId>
      <version>${cucumber.version}</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>io.cucumber</groupId>
      <artifactId>cucumber-junit-platform-engine</artifactId>
      <version>${cucumber.version}</version>
      <scope>test</scope>
    </dependency>

没有一个例子我可以在黄瓜文档中找到我尝试融合一些我在网上找到的片段,这些片段显示这个依赖列表是足够的但是,当我尝试他们的样本时,我找不到以下任何一个:

  1. CucumberExtension - 相反,有一个注释 @Cucumber 似乎正在这样做。
  2. @CucumberOptions - 有一个我可以实现的接口 CucmberOptions 和 return 所有必需的属性,但这感觉就像是参数化注释的倒退。

任何人都可以提供指南、文档或任何其他方式来实现我的目标吗?

谢谢

JUnit 5 的介绍值得一读。您犯了一个常见错误,认为 JUnit 5 是一个整体。相反:

https://junit.org/junit5/docs/current/user-guide/#overview-what-is-junit-5

Unlike previous versions of JUnit, JUnit 5 is composed of several different modules from three different sub-projects.

JUnit 5 = JUnit Platform + JUnit Jupiter + JUnit Vintage

与 JUnit Jupiter 一样,Cucumber 是一个使用 JUnit 平台的测试引擎。扩展是 JUnit Jupiter 的一个概念,不会延续到 Cucumber。

Without a single example I could find in the cucumber documentation.

在 JUnit 5 集成功能完成之前,您将无法在主文档中找到任何内容。在那之前,完全可以使用 Cucumbers JUnit 4 与 JUnit Vintage 的集成。

但是,如果您更注重实验,可以使用带有源代码的文档:

https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine

@CucumberOptions - there is an interface CucmberOptions which I can implement and return all required properties, but this feels like a step back from the parameterized annotation.

Cucumber JUnit Platform 集成默认扫描 class 路径根上的粘合和功能。如果您遵循传统的 maven/gradle/java 项目布局,则不需要额外的配置。

所以步骤定义在 src/test/java/com/example 中,特征在 src/test/resources/com/example 中。

如果您有更复杂的设置,您应该等待并使用 JUnit4/Junit Vintage 或简化您的设置。