Cucumber-junit-platform-engine 中的特征文件发现

mak*_*aki 5 java cucumber gradle cucumber-junit junit5

cucumber-junit库中,我@CucumberOptions用来定义特征文件位置:

package com.mycompany.cucumber;

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

@RunWith(Cucumber.class)
@CucumberOptions(
  plugin = ...,
  features = "classpath:.", // my java step definitions are in package com.mycompany.cucumber 
                            // but feature files directly in test resources 
                            // resources/is_it_friday_yet.feature
  tags = ...,
  glue = ...
)
public class CucumberRunner {
}
Run Code Online (Sandbox Code Playgroud)

我正在使用自定义 gradle 任务运行我的测试 cucumberTest

cucumberTest {
    useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)

迁移后cucumber-junit-platform-engine @CucumberOptions不再支持。

cucumberTest {
    useJUnitPlatform()
}
Run Code Online (Sandbox Code Playgroud)

我可以通过用属性替换plugin, tags,glue选项使其工作cucumber.filter.tagscucumber.glue, cucumber.plugin

什么features财产?如果我更改功能文件位置以匹配包名称,即resources/com/mycompany/cucumber/is_it_friday_yet.feature. 这仍然是一个简单的案例,我有更多的测试包,它们没有与源代码放在相同的位置,我无法移动它们。

spm*_*son 7

在 cucumber-jvm v7 中,@Cucumber注释已被弃用,并且鼓励您使用常规@Suite注释。这对我有用:

@Suite
@IncludeEngines("cucumber")
@SelectClasspathResource("features")
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.cucumber")
public class CucumberIT {
}
Run Code Online (Sandbox Code Playgroud)

它会拾取features/我的资源文件夹(类路径)中的目录下的所有 .feature 文件

注解的目的:
@Suite - JUnit 5 的注解使此类成为测试套件的运行配置。
@IncludeEngines("cucumber") - 告诉 JUnit 5 使用 Cucumber 测试引擎来运行功能。
@SelectClasspathResource("features") - 更改功能文件的位置(如果不添加此注释,将使用当前类的类路径)。
@ConfigurationParameter(key = GLUE_PROPERTY_NAME, value = "com.mycompany.cucumber") - 此注释指定步骤定义(java 类)的路径。

文档:https://github.com/cucumber/cucumber-jvm/tree/main/junit-platform-engine#suites-with- different-configurations

junit-platform 支持各种其他@Select*注释,我认为这些注释也有效(尽管它们被标记为实验性的,因此可能会发生变化): https: //junit.org/junit5/docs/current/user-guide/# api-进化-实验-api

  • 在 cucumber-jvm 6.9.1 中怎么样? (2认同)