Skip to content

Commit

Permalink
Merge pull request #89 from whatever-mentoring/feature/jacoco-plugin
Browse files Browse the repository at this point in the history
Add jacoco plugin for showing test coverage
  • Loading branch information
mkSpace committed Mar 28, 2024
2 parents cdd3128 + 462765c commit c19990c
Showing 1 changed file with 91 additions and 3 deletions.
94 changes: 91 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ plugins {
kotlin("plugin.spring") version "1.9.20"
kotlin("plugin.jpa") version "1.9.20"
kotlin("kapt") version "1.6.21"
jacoco
}

java.sourceCompatibility = JavaVersion.VERSION_17
Expand Down Expand Up @@ -35,6 +36,7 @@ subprojects {
apply(plugin = "io.spring.dependency-management")
apply(plugin = "kotlin-kapt")
apply(plugin = "application")
apply(plugin = "jacoco")

dependencies {
implementation("org.springframework.boot:spring-boot-starter-web")
Expand All @@ -49,15 +51,101 @@ subprojects {
testRuntimeOnly("com.h2database:h2")
}

tasks.withType<KotlinCompile> {
jacoco {
toolVersion = "0.8.11"
}

tasks.jacocoTestReport {
dependsOn(tasks.test)
reports {
html.required = true
html.outputLocation = layout.buildDirectory.dir("reports/test-coverage.html").get().asFile
csv.required = false
xml.required = false
}

val excludes = listOf(
"com/whatever/raisedragon/config",
"com/whatever/raisedragon/common",
"com/whatever/raisedragon/infra",
"com/whatever/raisedragon/common/config",
"com/whatever/raisedragon/aws",
"com/whatever/raisedragon/applicationservice/*/dto"
)

classDirectories.setFrom(
sourceSets.main.get().output.asFileTree.matching {
exclude(excludes)
}
)

finalizedBy(tasks.jacocoTestCoverageVerification)
}

tasks.jacocoTestCoverageVerification {
val qDomains = mutableListOf<String>()

for (qPattern in 'A'..'Z') {
qDomains.add("*.Q${qPattern}*")
}

violationRules {
rule {
enabled = true
element = "CLASS"

limit {
counter = "BRANCH"
value = "COVEREDRATIO"
// TODO Fix minimum ratio after increasing test coverage ratio
minimum = "0.00".toBigDecimal()
}

limit {
counter = "LINE"
value = "TOTALCOUNT"
maximum = "200".toBigDecimal()
// TODO Fix minimum ratio after increasing test coverage ratio
minimum = "0.00".toBigDecimal()
}

excludes = qDomains
}
}

val excludes = listOf(
"com/whatever/raisedragon/config",
"com/whatever/raisedragon/common",
"com/whatever/raisedragon/infra",
"com/whatever/raisedragon/common/config",
"com/whatever/raisedragon/aws",
"com/whatever/raisedragon/applicationservice/*/dto"
)

classDirectories.setFrom(
sourceSets.main.get().output.asFileTree.matching {
exclude(excludes)
}
)
}

tasks.test {
useJUnitPlatform()
finalizedBy(tasks.jacocoTestReport)
}

tasks.compileKotlin {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}

tasks.withType<Test> {
useJUnitPlatform()
tasks.compileTestKotlin {
kotlinOptions {
freeCompilerArgs = listOf("-Xjsr305=strict")
jvmTarget = "17"
}
}

tasks.bootJar {
Expand Down

0 comments on commit c19990c

Please sign in to comment.