1
我想測量Jacoco在model
項目中的覆蓋範圍,該項目是兒童項目之一。 但是,test
任務後,jacocoTestReport
任務被跳過。如何在多項目中設置Jacoco with Spek?
test
:
:model:compileKotlin UP-TO-DATE
:model:compileJava UP-TO-DATE
:model:copyMainKotlinClasses UP-TO-DATE
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:compileTestKotlin UP-TO-DATE
:model:compileTestJava UP-TO-DATE
:model:copyTestKotlinClasses UP-TO-DATE
:model:processTestResources UP-TO-DATE
:model:testClasses UP-TO-DATE
3 10, 2017 8:17:48 org.junit.platform.launcher.core.ServiceLoaderTestEngineRegistry loadTestEngines
Discovered TestEngines with IDs: [spek]
:model:junitPlatformTest
Test run finished after 113 ms
[ 4 containers found ]
[ 0 containers skipped ]
[ 4 containers started ]
[ 0 containers aborted ]
[ 4 containers successful ]
[ 0 containers failed ]
[ 1 tests found ]
[ 0 tests skipped ]
[ 1 tests started ]
[ 0 tests aborted ]
[ 1 tests successful ]
[ 0 tests failed ]
:model:test
:model:test SKIPPED
然後,XML文件輸出。 (型號/建設/測試結果/ JUnit的平臺/ TEST-spek.xml)
jacocoTestReport
:
:model:compileKotlin UP-TO-DATE
:model:compileJava UP-TO-DATE
:model:copyMainKotlinClasses UP-TO-DATE
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:jacocoTestReport SKIPPED
的build.gradle:
buildscript {
ext.kotlinVersion = '1.1.0'
repositories {
mavenLocal()
mavenCentral()
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "org.junit.platform:junit-platform-gradle-plugin:1.0.0-M3"
}
}
allprojects {
ext {
spekVersion = '1.1.0-beta3'
}
repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url "http://dl.bintray.com/jetbrains/spek" }
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
}
}
project(":model") {
apply plugin: "java"
apply plugin: "kotlin"
apply plugin: 'org.junit.platform.gradle.plugin'
apply plugin: "jacoco"
jacoco {
reportsDir = file("$rootProject.buildDir/reports/jacoco")
}
jacocoTestReport {
reports {
html.enabled = true
xml.enabled = true
csv.enabled = false
}
}
junitPlatform {
filters {
engines {
include 'spek'
}
}
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlinVersion"
testCompile "org.jetbrains.spek:spek-api:$spekVersion"
testCompile 'org.amshove.kluent:kluent:1.14'
testRuntime "org.jetbrains.spek:spek-junit-platform-engine:$spekVersion"
testRuntime 'org.junit.platform:junit-platform-console:1.0.0-M3'
}
}
我應該怎麼做才能讓jacocoTestReport
任務成功?
[編輯]
當我添加onlyIf
,jacocoTestReport
任務運行,但它仍然失敗。
jacocoTestReport {
onlyIf = {
true
}
}
輸出:
:model:compileKotlin UP-TO-DATE
:model:compileJava UP-TO-DATE
:model:copyMainKotlinClasses UP-TO-DATE
:model:processResources UP-TO-DATE
:model:classes UP-TO-DATE
:model:jacocoTestReport FAILED
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':model:jacocoTestReport'.
> Unable to read execution data file model\build\jacoco\test.exec
這可能有助於http://stackoverflow.com/a/42520303/1425525 – raniejade
是它有用嗎?由於在另一個問題中不是太有用,所以我可以在這裏移動它。 –