问题描述
在cumulan-junit中,我使用@CucumberOptions
定义特征文件的位置:
In cucumber-junit I use @CucumberOptions
to define feature files loacation:
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
I'm running my tests with custom gradle task cucumberTest
cucumberTest {
useJUnitPlatform()
}
迁移到cucumber-junit-platform-engine
@CucumberOptions
后不再受支持.
After migrating to cucumber-junit-platform-engine
@CucumberOptions
are no longer supported.
package com.mycompany.cucumber;
import io.cucumber.junit.platform.engine.Cucumber;
@Cucumber
public class CucumberRunner {
}
我可以用属性cucumber.filter.tags
,cucumber.glue
,cucumber.plugin
替换plugin
,tags
,glue
选项来使其工作.
I can make it work with replacing plugin
, tags
, glue
options with properties cucumber.filter.tags
, cucumber.glue
, cucumber.plugin
.
features
属性如何?如果我更改功能文件的位置以匹配程序包名称(即resources/com/mycompany/cucumber/is_it_friday_yet.feature
),则效果很好.仍然这是一个简单的案例,我有更多的测试包,它们与源代码的位置不同,因此无法移动它们.
What about features
property? It works fine if I change feature files location to match package name i.e. resources/com/mycompany/cucumber/is_it_friday_yet.feature
. Still this is a simple case and I have many more test packages which are not placed in the same locations as source code and I cannot move them.
推荐答案
Gradle不支持基于非类的测试引擎.但是,您可以创建自定义任务使用JUnit Platform ConsoleLauncher .然后,您可以使用 Junit 5选择器是由Cucumber支持以选择您的功能.例如FileSelector
和--select-file
.
Gradle doesn't support non-class based test engines. However you can create a custom task that uses the JUnit Platform ConsoleLauncher. You can then use the Junit 5 selectors that are supported by Cucumber to select your features. For example the FileSelector
with --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)
}
这篇关于Cucumber-junit-platform-engine中的功能文件发现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!