在 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 selectors是 supported 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/