From b81964fa234d3cfb297d5887b35e7df02ce12bdf Mon Sep 17 00:00:00 2001 From: Victor Smirnov <53015676+vityaman@users.noreply.github.com> Date: Wed, 20 Mar 2024 14:52:34 +0300 Subject: [PATCH] #12 Added Kover to check test coverage (#16) --- .github/workflows/gradle.yml | 8 +++-- gateway/build.gradle.kts | 30 ++++++++++++++++--- .../lms/gateway/GatewayApplicationTests.kt | 16 ++++++++-- 3 files changed, 46 insertions(+), 8 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index c628898..2baf95e 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -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) + diff --git a/gateway/build.gradle.kts b/gateway/build.gradle.kts index 881692e..4f20986 100644 --- a/gateway/build.gradle.kts +++ b/gateway/build.gradle.kts @@ -9,6 +9,7 @@ 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" } @@ -16,6 +17,9 @@ plugins { group = "ru.itmo" version = "0.0.1" +val jvmTarget = "21" +val basePackage = "$group.lms.gateway" + java { sourceCompatibility = JavaVersion.VERSION_21 } @@ -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 { kotlinOptions { freeCompilerArgs += "-Xjsr305=strict" - jvmTarget = "21" + jvmTarget = jvmTarget } } @@ -60,7 +65,7 @@ val generateControllers = "generateControllers" tasks.register(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" @@ -131,9 +136,26 @@ tasks.withType().configureEach { } tasks.withType().configureEach { - jvmTarget = "21" + jvmTarget = jvmTarget } tasks.withType().configureEach { - jvmTarget = "21" + jvmTarget = jvmTarget +} + +koverReport { + filters { + excludes { + classes( + "$basePackage.api.http.apis.*", + "$basePackage.GatewayApplicationKt", + ) + } + } + verify { + rule { + isEnabled = true + bound { minValue = 80 } + } + } } diff --git a/gateway/src/test/kotlin/ru/itmo/lms/gateway/GatewayApplicationTests.kt b/gateway/src/test/kotlin/ru/itmo/lms/gateway/GatewayApplicationTests.kt index 5431a9e..91cab03 100644 --- a/gateway/src/test/kotlin/ru/itmo/lms/gateway/GatewayApplicationTests.kt +++ b/gateway/src/test/kotlin/ru/itmo/lms/gateway/GatewayApplicationTests.kt @@ -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") } }