【发布时间】:2020-02-28 10:05:27
【问题描述】:
我的项目结构如下,
--项目
--道
--服务
--控制器
--测试
--build.gradle.kts
我在控制器中只有集成测试。我所有的子模块(DAO、服务和控制器)都是 gradle 项目,其中包含 build.gradle.kts。
以下是我的父模块中的 build.gradle.kts,即在项目中
import org.jetbrains.dokka.gradle.DokkaTask
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
val Project.`java`: JavaPluginConvention
get() = convention.getPluginByName("java")
plugins {
val kotlinVersion = "1.3.61"
val testLoggerVersion = "1.6.0"
val dokkaVersion = "0.9.18"
base
jacoco
kotlin("jvm") version kotlinVersion apply false
maven
id("com.adarshr.test-logger") version testLoggerVersion apply false
id("org.jetbrains.dokka") version dokkaVersion apply false
}
jacoco {
toolVersion = jacocoVersion
reportsDir = file("$buildDir/reports/jacoco")
}
allprojects {
version = "dev"
repositories {
jcenter()
mavenCentral()
}
}
subprojects {
apply {
plugin("kotlin")
plugin("jacoco")
plugin("com.adarshr.test-logger")
plugin("org.jetbrains.dokka")
}
dependencies {
"implementation"(kotlin("stdlib"))
"implementation"("org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlinxCoroutinesVersion")
"implementation"("com.fasterxml.jackson.module:jackson-module-kotlin:$fasterxmlVersion")
"implementation"("com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$fasterxmlVersion")
"implementation"("org.koin:koin-core:$koinVersion")
"testImplementation"("org.koin:koin-test:$koinVersion")
"testImplementation"("io.mockk:mockk:$mockkVersion")
"testImplementation"("org.junit.jupiter:junit-jupiter-api:$jUnitVersion")
"testImplementation"("org.junit.jupiter:junit-jupiter-params:$jUnitVersion")
"testImplementation"("org.testcontainers:junit-jupiter:$testcontainersVersion")
"testImplementation"("org.testcontainers:testcontainers:$testcontainersVersion")
"testImplementation"("org.testcontainers:postgresql:$testcontainersVersion")
"testRuntime"("org.junit.jupiter:junit-jupiter-engine:$jUnitVersion")
}
tasks.register<Jar>("uberJar") {
archiveClassifier.set("uber")
from(java.sourceSets["main"].output)
dependsOn(configurations["runtimeClasspath"])
from({
configurations["runtimeClasspath"]
.filter { it.name.endsWith("jar") }
.map { zipTree(it) }
})
}
tasks.register<Zip>("uberZip") {
from(java.sourceSets["main"].output)
dependsOn(configurations["runtimeClasspath"])
from({
configurations["runtimeClasspath"]
.filter { it.name.endsWith("jar") }
.map { zipTree(it) }
})
}
tasks.withType<DokkaTask> {
outputFormat = "html"
outputDirectory = "$buildDir/javadoc"
}
tasks.withType<KotlinCompile> {
sourceCompatibility = javaVersion
targetCompatibility = javaVersion
kotlinOptions {
jvmTarget = javaVersion
apiVersion = kotlinVersion
languageVersion = kotlinVersion
}
}
tasks.withType<JacocoReport> {
reports {
html.apply {
isEnabled = true
destination = file("$buildDir/reports/jacoco")
}
csv.isEnabled = false
}
afterEvaluate {
classDirectories.setFrom(files(classDirectories.files.map {
fileTree(it).apply {
exclude("io/company/common/aws/test/support/**")
exclude("io/company/common/system/**")
}
}))
}
}
tasks.withType<Test> {
useJUnitPlatform()
testLogging.showStandardStreams = true
testLogging {
events("PASSED", "FAILED", "SKIPPED", "STANDARD_OUT", "STANDARD_ERROR")
}
}
}
我的问题是 jacoco 代码覆盖率。当我运行./gradlew clean test jacocoTestReport 时,我只得到我的控制器而不是服务和 daos 的覆盖范围。
我的 gradle 版本是 5.4.1。
如何获得涵盖所有测试模块的测试覆盖率综合报告? 我尝试了来自 stackoverflow 的多个链接,但没有运气。
【问题讨论】: