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

标签 java gradle cucumber junit5 cucumber-junit

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 {
}
我正在使用自定义 gradle 任务运行我的测试 cucumberTest
cucumberTest {
    useJUnitPlatform()
}
迁移到 cucumber-junit-platform-engine@CucumberOptions不再支持。
package com.mycompany.cucumber;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class CucumberRunner {
}
我可以通过替换 plugin 让它工作, tags , glue带有属性的选项 cucumber.filter.tags , cucumber.glue , cucumber.plugin .
怎么样features属性(property)?如果我更改功能文件位置以匹配包名称,即 resources/com/mycompany/cucumber/is_it_friday_yet.feature,它工作正常.这仍然是一个简单的案例,我有更多的测试包,它们没有与源代码放在相同的位置,我无法移动它们。

最佳答案

Gradle doesn't support non-class based test engines .但是您可以创建 a custom task that uses the JUnit Platform ConsoleLauncher .然后您可以使用 Junit 5 selectorssupported by Cucumber选择您的功能。例如 FileSelector--select-file .

val consoleLauncherTest by tasks.creating(JavaExec::class) {
    dependsOn("testClasses")
    val reportsDir = file("$buildDir/test-results")
    outputs.dir(reportsDir)
    classpath(sourceSets["test"].runtimeClasspath)
    main = "org.junit.platform.console.ConsoleLauncher"
    args("--select-file", "path/to.feature")
    args("--details", "tree")
    args("--reports-dir", reportsDir)
}

关于java - Cucumber-junit-platform-engine 中的特征文件发现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64676559/

相关文章:

java - Spring JUnit Mockito 单元测试 Controller 指定的类是一个接口(interface)

android - 在存储库容器上找不到参数 [] 的方法 google()。 ( flutter )

eclipse-plugin - Eclipse Gradle插件:Gradle依赖项有时会更改 'order and export'屏幕中的位置

ruby-on-rails - 如何告诉 capybara-webkit 不要忽略确认框(或者只是测试它们的内容)

ruby-on-rails - 我如何断言 Cucumber 中模型的存在?

java - Box2D/AndEngine - 用于多个对象类的 ContactListener

java - Spring:xml配置转换为java配置

java - 有没有办法操作 Cucumber 数据表中的值?

java - 如何使用 Java 生成 javadoc?

java - 我们可以使用为Linux编译的 ".so"库到android中吗?