Skip to content

Commit

Permalink
#12 Added Kover to check test coverage (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman authored Mar 20, 2024
1 parent 419ee7d commit b81964f
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
8 changes: 6 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ jobs:
- name: Setup Gradle
uses: gradle/actions/setup-gradle@v3

- name: Execute Gradle Build of Gateway
run: (cd gateway && ./gradlew build)
- name: Build Gateway
run: (cd gateway && ./gradlew :build)

- name: Test Gateway
run: (cd gateway && ./gradlew :koverHtmlReport)

30 changes: 26 additions & 4 deletions gateway/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@ plugins {
id("org.openapi.generator") version "5.3.0"
id("org.jlleitschuh.gradle.ktlint") version "12.1.0"
id("io.gitlab.arturbosch.detekt") version "1.23.5"
id("org.jetbrains.kotlinx.kover") version "0.7.6"
kotlin("jvm") version "1.9.22"
kotlin("plugin.spring") version "1.9.22"
}

group = "ru.itmo"
version = "0.0.1"

val jvmTarget = "21"
val basePackage = "$group.lms.gateway"

java {
sourceCompatibility = JavaVersion.VERSION_21
}
Expand All @@ -41,13 +45,14 @@ dependencies {
annotationProcessor("org.springframework.boot:spring-boot-configuration-processor")
testImplementation("org.springframework.boot:spring-boot-starter-test")
testImplementation("io.projectreactor:reactor-test")
testImplementation(kotlin("test"))
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.3")
}

tasks.withType<KotlinCompile> {
kotlinOptions {
freeCompilerArgs += "-Xjsr305=strict"
jvmTarget = "21"
jvmTarget = jvmTarget
}
}

Expand All @@ -60,7 +65,7 @@ val generateControllers = "generateControllers"

tasks.register<GenerateTask>(generateControllers) {
val spec = "${layout.projectDirectory}/src/main/resources/static/openapi/api.yml"
val pkg = "ru.itmo.lms.gateway.api.http"
val pkg = "$basePackage.api.http"

group = "openapi tools"
description = "Generates code from an Open API specification"
Expand Down Expand Up @@ -131,9 +136,26 @@ tasks.withType<Detekt>().configureEach {
}

tasks.withType<Detekt>().configureEach {
jvmTarget = "21"
jvmTarget = jvmTarget
}

tasks.withType<DetektCreateBaselineTask>().configureEach {
jvmTarget = "21"
jvmTarget = jvmTarget
}

koverReport {
filters {
excludes {
classes(
"$basePackage.api.http.apis.*",
"$basePackage.GatewayApplicationKt",
)
}
}
verify {
rule {
isEnabled = true
bound { minValue = 80 }
}
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,24 @@
package ru.itmo.lms.gateway

import kotlinx.coroutines.runBlocking
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import ru.itmo.lms.gateway.api.http.apis.MonitoringApi
import kotlin.test.assertEquals

@SpringBootTest
class GatewayApplicationTests {
class GatewayApplicationTests(
@Autowired val monitoringApi: MonitoringApi,
) {
@Test
fun contextLoads() {
// Do nothing
// Okay
}

@Test
fun pingSucceeds() {
val body = runBlocking { monitoringApi.monitoringPingGet().body }
assertEquals(body, "pong")
}
}

0 comments on commit b81964f

Please sign in to comment.