如何在多项目中使用Spek来设置Jacoco?
我想要测量雅科科在儿童项目之一的model
项目中的覆盖面。 然而,在test
任务之后, jacocoTestReport
任务被跳过。
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
默认情况下,JUnit Gradle插件禁用标准的Gradle测试任务,但可以通过enableStandardTestTask标志覆盖。 看来jacocoTestReport任务正在寻找。
junitPlatform { filters { engines { include 'spek' } } enableStandardTestTask true }
请参阅http://junit.org/junit5/docs/current/user-guide/#running-tests-build