[英]How to run the cucumber test using gradle
我在 Gradle 中運行 Cucumber 測試時遇到問題。 我正在使用黃瓜 jvm。
類TestNGCucumberRunner
使用@beforesuite
, @aftersuite
.. 擴展了AbstractTestNGCucumberTests
和 testng 注釋。
我通常通過右鍵單擊在 IntelliJ 中運行TestNGCucumberRunner.java
並成功運行。 現在我想
或者
我試圖將 TestNGCucumberRunner.java 作為 javaexec 執行,但失敗了。
我試圖執行包中的所有功能文件。 我也使用了apply plugin: 'com.github.samueltbrown.cucumber'
。
我的新設置使用了一個不同的 插件,該 插件支持場景的並行執行、更好的報告,並且仍在積極維護:
構建.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
package1和package2名稱(連同許多其他選項)可以在 build.gradle 文件中指定
我之前在 gradle 中使用 Cucumber for java 的設置。
構建.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
我選擇不使用com.github.samueltbrown.cucumber
插件,它最后一次更新是在 2015 年 8 月。相反,我創建了一個我可以獨立構建的“integrationTest”(cucumber)源集。 即,一個簡單的gradle build
將構建test
和integrationTest
test
源集。 如果我只想運行集成測試,我可以運行gradle integrationTest -x test
,或者我只能運行帶有gradle test -x integrationTest
。
我遵循的步驟在這里: http : //www.petrikainulainen.net/programming/gradle/getting-started-with-gradle-integration-testing/
但這里是總結:
構建.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'
)
}
你可以閱讀官方文件。
Cucumber 文檔不使用 gradle Test 任務類型,因此不存在某些集成(特別是 Jacoco)。 我仍在尋找一種方法來獲取測試任務以在運行測試時執行黃瓜主要任務。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.