Skip to content

Commit 5ec6780

Browse files
committed
jacoco test coverage
1 parent dc4e258 commit 5ec6780

File tree

2 files changed

+82
-6
lines changed

2 files changed

+82
-6
lines changed

build.gradle.kts

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ plugins {
55
application
66
id("com.github.davidmc24.gradle.plugin.avro") version "1.9.1"
77
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
8+
jacoco
89
}
910

1011
group = "com.dragos"
@@ -61,20 +62,23 @@ tasks.withType<KotlinCompile> {
6162

6263
tasks.withType<Test> {
6364
useJUnitPlatform()
64-
65+
6566
// Set Docker socket for Testcontainers when using Colima
6667
val dockerSocket = "${System.getProperty("user.home")}/.colima/default/docker.sock"
6768
environment("DOCKER_HOST", "unix://$dockerSocket")
6869
environment("TESTCONTAINERS_DOCKER_SOCKET_OVERRIDE", dockerSocket)
69-
70+
7071
// IMPORTANT: Disable Ryuk for Colima compatibility
7172
environment("TESTCONTAINERS_RYUK_DISABLED", "true")
72-
73+
7374
testLogging {
7475
events("passed", "skipped", "failed")
7576
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
7677
showStandardStreams = true
7778
}
79+
80+
// Generate coverage report after tests
81+
finalizedBy(tasks.jacocoTestReport)
7882
}
7983

8084
// Fat JAR configuration
@@ -100,16 +104,88 @@ ktlint {
100104
android.set(false)
101105
outputToConsole.set(true)
102106
ignoreFailures.set(false)
103-
107+
104108
filter {
105109
exclude("**/generated/**")
110+
exclude("**/build/**")
106111
include("**/kotlin/**")
107112
}
108113
}
109114

115+
// Fix ktlint dependency on Avro generation
116+
tasks.named("runKtlintCheckOverMainSourceSet") {
117+
dependsOn("generateAvroJava")
118+
}
119+
120+
tasks.named("runKtlintCheckOverTestSourceSet") {
121+
dependsOn("generateTestAvroJava")
122+
}
123+
124+
tasks.named("runKtlintFormatOverMainSourceSet") {
125+
dependsOn("generateAvroJava")
126+
}
127+
128+
tasks.named("runKtlintFormatOverTestSourceSet") {
129+
dependsOn("generateTestAvroJava")
130+
}
131+
132+
// JaCoCo configuration
133+
jacoco {
134+
toolVersion = "0.8.11"
135+
}
136+
137+
tasks.jacocoTestReport {
138+
dependsOn(tasks.test)
139+
140+
reports {
141+
xml.required.set(true)
142+
html.required.set(true)
143+
csv.required.set(false)
144+
}
145+
146+
classDirectories.setFrom(
147+
files(
148+
classDirectories.files.map {
149+
fileTree(it) {
150+
exclude(
151+
"**/generated/**",
152+
)
153+
}
154+
},
155+
),
156+
)
157+
}
158+
159+
tasks.jacocoTestCoverageVerification {
160+
dependsOn(tasks.jacocoTestReport)
161+
162+
violationRules {
163+
rule {
164+
limit {
165+
minimum = "0.80".toBigDecimal() // 80% minimum coverage
166+
}
167+
}
168+
169+
rule {
170+
element = "CLASS"
171+
limit {
172+
counter = "LINE"
173+
value = "COVEREDRATIO"
174+
minimum = "0.70".toBigDecimal() // 70% per class
175+
}
176+
excludes =
177+
listOf(
178+
"*.Main*",
179+
"*.*Kt",
180+
)
181+
}
182+
}
183+
}
184+
110185
// Make build depend on ktlint checks
111186
tasks.named("check") {
112187
dependsOn("ktlintCheck")
188+
dependsOn("jacocoTestCoverageVerification")
113189
}
114190

115191
// Auto-format code before compiling
@@ -119,4 +195,4 @@ tasks.named("compileKotlin") {
119195

120196
tasks.named("compileTestKotlin") {
121197
dependsOn("ktlintFormat")
122-
}
198+
}

settings.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
rootProject.name = "kafka-csv-loader"
1+
rootProject.name = "kafka-csv-loader"

0 commit comments

Comments
 (0)