如何解决Cucumber-junit-platform-engine中的功能文件发现
在cumulan-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
属性如何?如果我更改功能文件的位置以匹配程序包名称(即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)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。