我正在尝试使用新的Cucumber-jvm系统和Gradle作为我的构建系统来启动一个项目。
我在GitHub cucumber-jvm项目(https://github.com/cucumber/cucumber-jvm)中使用了示例Java代码。
我的项目是在IntelliJ中设置的,并且能够运行测试。
但是,Gradle找不到任何要运行的测试。我之所以知道这一点,是因为我考砸了,而Gradle什么也没说。它在工作时也没有显示任何内容。
它试图运行的类如下所示:
import cucumber.junit.Cucumber;
import cucumber.junit.Feature;
import org.junit.runner.RunWith;
@RunWith(Cucumber.class)
@Feature(value = "CarMaintenance.feature")
public class FuelCarTest {
}我对黄瓜和Gradle都是新手!
发布于 2013-12-23 20:50:16
我记得Gradle和Cucumber在junit runner上遇到了麻烦。我最终放弃了,使用命令行运行程序创建了一个gradle任务。
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath, file(webAppDir.path + '/WEB-INF/classes'))
args += [ '-f', 'html:build/reports/cucumber', '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}用于html报告输出的-f文件夹
粘合/步骤代码的-g包名称
要素文件所在的src/test/resources/features
具有以下依赖项
testCompile 'org.mockito:mockito-all:1.9.5',
'junit:junit:4.11',
'org.hamcrest:hamcrest-library:1.3',
'info.cukes:cucumber-java:1.0.14',
'info.cukes:cucumber-junit:1.0.14',
'info.cukes:cucumber-spring:1.0.14'4.2.5版的更新
随着时间的推移,有了一些小的变化:
cucumber.api.cli.Main-f似乎不再起作用,并导致错误因此,我在build.gradle中完成了以下任务定义
task executeFeatures(type: JavaExec, dependsOn: testClasses) {
main = "cucumber.api.cli.Main"
classpath += files(sourceSets.test.runtimeClasspath)
args += [ '-g', 'uk.co.filmtrader', 'src/test/resources/features']
}发布于 2018-11-27 18:15:18
另一种方法是创建任务并包含用于测试的runner类
build.gradle-
task RunCukesTest(type: Test) << {
include "RunCukesTest.class"
}
testCompile 'io.cucumber:cucumber-java:4.2.0'
testCompile 'io.cucumber:cucumber-junit:4.2.0'
your class -
@RunWith(Cucumber.class)
@CucumberOptions(dryRun = false, strict = true, features = "src/test/resources", glue
= "com.gradle.featuretests",monochrome = true)
public class RunCukesTest {
}只需点击命令:- gradle RunCukesTest
发布于 2020-07-24 06:56:57
考虑:
.feature文件在src/test/resources/cucumber/features和中,而glue类在com.example.myapp.glue中
然后,在explained in the docs之后,您可以在build.gradle中执行以下操作
dependencies {
// ...
testImplementation("io.cucumber:cucumber-java:6.2.2")
testImplementation("io.cucumber:cucumber-junit:6.2.2")
testImplementation("io.cucumber:cucumber-junit-platform-engine:6.2.2")
}
configurations {
cucumberRuntime {
extendsFrom testImplementation
}
}
// this enables the task `gradle cucumber`
task cucumber() {
dependsOn assemble, compileTestKotlin
doLast {
javaexec {
main = "io.cucumber.core.cli.Main"
classpath = configurations.cucumberRuntime + sourceSets.main.output + sourceSets.test.output
args = ['--strict', '--plugin', 'pretty', '--plugin', 'junit:build/test-results/cucumber.xml', '--glue', 'com.example.myapp.glue', 'src/test/resources/cucumber/features']
}
}
}
// (OPTIONAL) this makes `gradle test` also include cucumber tests
tasks.test {
finalizedBy cucumber
}现在,gradle cucumber将运行黄瓜测试。
如果添加了最后一部分,gradle test还将运行黄瓜测试。
args部件支持运行器的@CucumberOptions注释中的内容。更多细节:https://cucumber.io/docs/cucumber/api/#list-configuration-options
https://stackoverflow.com/questions/9292311
复制相似问题