我在Gradle中运行Cucumber测试时遇到问题。我正在使用cucumber-jvm。
类TestNGCucumberRunner
使用AbstractTestNGCucumberTests
,@beforesuite
扩展@aftersuite
和testng注释..
我通常通过右键单击在IntelliJ中运行TestNGCucumberRunner.java
并成功运行。现在我想
或
我尝试将testNGCucumberRunner.java作为javaexec执行,但失败了。
我尝试执行包中的所有功能文件。我也使用了apply plugin: 'com.github.samueltbrown.cucumber'
。
答案 0 :(得分:8)
我的新设置使用了不同的plugin,支持并行执行方案,更好的报告,并且仍然得到积极维护:
<强>的build.gradle 强>
plugins {
...
id "com.commercehub.cucumber-jvm" version "0.11"
}
addCucumberSuite 'cucumberTest'
dependencies {
...
cucumberTestCompile 'info.cukes:cucumber-java:1.2.5' // or -java8 if you prefer lambda notation
}
目录结构:
└── src
├── cucumberTest
│ ├── java
│ │ └── package1
│ └── <- Glue
│ └── resources
│ └── package2
│ └── <- Features
├── main
│ └── java
└── test
└── java
可以在build.gradle文件中指定package1 和 package2 名称(以及许多其他options)
我的之前的设置,用于使用带有gradle的java的黄瓜。
<强>的build.gradle 强>
plugins {
id "java"
id "com.github.samueltbrown.cucumber" version "0.9"
}
dependencies {
cucumberCompile 'info.cukes:cucumber-java:1.2.4'
}
cucumber {
formats = ['pretty','junit:build/cucumber.xml']
}
目录布局
└── src
├── cucumber
│ ├── java <- Glue
│ └── resources <- Features
└── main
│ └── java
└── test
└── java
<强>命令强>
gradle cucumber
答案 1 :(得分:4)
我选择不使用com.github.samueltbrown.cucumber
插件,它最后一次更新于2015年8月。相反,我创建了一个“integrationTest”(黄瓜)sourceSet,我可以独立构建。即,简单的gradle build
将构建test
和integrationTest
源集。如果我只想运行集成测试,我可以运行gradle integrationTest -x test
,或者我只能使用gradle test -x integrationTest
运行测试。
我遵循的步骤如下:http://www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/
但这是摘要:
的build.gradle
sourceSets {
integrationTest {
java {
compileClasspath += main.output + test.output
runtimeClasspath += main.output + test.output
srcDir file('src/integrationTest/java')
}
resources.srcDir file('src/integrationTest/resources')
}
}
//Ensure that the integrationTestCompile/integrationTestRuntime configuration contains the dependencies that are required to compile/run our unit tests.
configurations {
integrationTestCompile.extendsFrom testCompile
integrationTestRuntime.extendsFrom testRuntime
}
task integrationTest(type: Test) {
testClassesDir = sourceSets.integrationTest.output.classesDir
classpath = sourceSets.integrationTest.runtimeClasspath
// Gradle skips tasks whose input and output are up to date.
// To ensure that your integration tests are run every time,
// tell Gradle that the outputs of the integrationTest task should always be considered out of date.
outputs.upToDateWhen { false }
}
// Ensure that our integration tests are run before the check task and that the check task fails the build if there are failing integration tests.
// Ensure that our unit tests are run before our integration tests. This guarantees that our unit tests are run even if our integration tests fails.
check.dependsOn integrationTest
integrationTest.mustRunAfter test
// Ensure that the HTML reports of unit and integration tests are created to different report
// build/reports/integrationTest directory contains the HTML report that contains the test results of our integration tests.
tasks.withType(Test) {
reports.html.destination = file("${reporting.baseDir}/${name}")
}
def cucumberVersion = "1.2.4"
dependencies {
integrationTestCompile(
'info.cukes:cucumber-core:' + cucumberVersion,
'info.cukes:cucumber-java:' + cucumberVersion,
'info.cukes:cucumber-java:' + cucumberVersion,
'info.cukes:cucumber-junit:' + cucumberVersion,
'info.cukes:cucumber-spring:' + cucumberVersion,
'org.springframework:spring-beans:4.2.5.RELEASE'
)
integrationTestRuntime(
'org.springframework:spring-context:4.2.5.RELEASE',
'org.springframework:spring-test:4.2.5.RELEASE',
'org.springframework:spring-tx:4.2.5.RELEASE'
)
}
答案 2 :(得分:3)
你可以阅读官方文件。
答案 3 :(得分:-1)
黄瓜文档不使用gradle Test任务类型,因此某些集成不存在(特别是Jacoco)。我仍在寻找一种方法,使其在运行测试时获得执行Test任务的执行权。