gpt4 book ai didi

unit-testing - 如何在多项目中使用Spek设置Jacoco?

转载 作者:行者123 更新时间:2023-12-02 12:48:38 26 4
gpt4 key购买 nike

我想衡量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

关于unit-testing - 如何在多项目中使用Spek设置Jacoco?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42717350/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com