diff --git a/.github/workflows/build-test.yaml b/.github/workflows/build-test.yaml index 21cd2f39..dda3bc61 100644 --- a/.github/workflows/build-test.yaml +++ b/.github/workflows/build-test.yaml @@ -21,5 +21,5 @@ jobs: distribution: 'temurin' java-version: '21' - - name: Build with Gradle - run: ./gradlew build \ No newline at end of file + - name: Run integration tests and build + run: ./gradlew integrationTest build diff --git a/Dockerfile b/Dockerfile index 5e2766d2..c7bf63dc 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,10 +1,10 @@ FROM gradle:8-jdk21-alpine AS build COPY --chown=gradle:gradle . /home/gradle/src WORKDIR /home/gradle/src -RUN gradle shadowjar --no-daemon +RUN gradle integrationTest shadowjar --no-daemon FROM eclipse-temurin:21-jdk-alpine EXPOSE 8080:8080 RUN mkdir /app COPY --from=build /home/gradle/src/build/libs/*.jar /app/matrikkel-bygning-egenregistrering.jar -ENTRYPOINT ["java", "-Dlogback.configurationFile=logback-cloud.xml", "-jar","/app/matrikkel-bygning-egenregistrering.jar"] \ No newline at end of file +ENTRYPOINT ["java", "-Dlogback.configurationFile=logback-cloud.xml", "-jar","/app/matrikkel-bygning-egenregistrering.jar"] diff --git a/README.md b/README.md index b995e12f..3c2eb653 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,7 @@ nødvendig rundt miljøkonfigurasjon, det skal ha sane defaults. ### Integrasjonstester -Prosjektet inneholder noen integrasjonstester som ligger under [src/intTest](src/intTest). Testene bruker blant annet +Prosjektet inneholder noen integrasjonstester som ligger under [src/intTest](src/integrationTest). Testene bruker blant annet testcontainers for å kjøre opp en database som bruke under testene. Testene er definert med en egen task som kan kjøres slik: diff --git a/build.gradle.kts b/build.gradle.kts index c7241b99..babef4c8 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,4 +1,6 @@ import com.github.jengelman.gradle.plugins.shadow.tasks.ShadowJar +import org.gradle.api.tasks.testing.logging.TestExceptionFormat +import org.gradle.api.tasks.testing.logging.TestLogEvent.* plugins { kotlin("jvm").version(libs.versions.kotlinVersion) @@ -6,6 +8,8 @@ plugins { alias(libs.plugins.ktor) alias(libs.plugins.shadow) + + `jvm-test-suite` } allprojects { @@ -17,17 +21,6 @@ application { mainClass.set("no.kartverket.matrikkel.bygning.ApplicationKt") } -sourceSets { - create("intTest") { - compileClasspath += sourceSets.main.get().output - runtimeClasspath += sourceSets.main.get().output - } -} - -val intTestImplementation: Configuration by configurations.getting { - extendsFrom(configurations.implementation.get()) -} - dependencies { implementation(project(":matrikkel-api")) @@ -59,14 +52,6 @@ dependencies { // OpenAPI implementation(libs.kompendium.core) - - // Integration tests - intTestImplementation(libs.kotlin.test) - intTestImplementation(libs.ktor.server.tests) - intTestImplementation(libs.ktor.client.content.negotation) - - intTestImplementation(libs.assertj) - intTestImplementation(libs.testcontainers.postgresql) } tasks { @@ -74,21 +59,37 @@ tasks { mergeServiceFiles() archiveBaseName.set("${project.name}-all") } +} - check { - dependsOn(integrationTest) +tasks.withType { + testLogging { + showCauses = true + showExceptions = true + exceptionFormat = TestExceptionFormat.FULL + events(PASSED, SKIPPED, FAILED) } } -val integrationTest = task("integrationTest") { - description = "Runs integration tests" - group = "verification" +@Suppress("UnstableApiUsage") +testing { + suites { + withType { + useJUnitJupiter() + } - testClassesDirs = sourceSets["intTest"].output.classesDirs - classpath = sourceSets["intTest"].runtimeClasspath - shouldRunAfter("test") + register("integrationTest") { + dependencies { + implementation(project()) - testLogging { - events("passed", "skipped", "failed") + implementation(libs.ktor.serialization.kotlinx) + + implementation(libs.kotlin.test) + implementation(libs.ktor.server.tests) + implementation(libs.ktor.client.content.negotation) + + implementation(libs.assertj) + implementation(libs.testcontainers.postgresql) + } + } } } diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index b6404468..5de2f219 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -35,7 +35,7 @@ logstash-encoder = { group = "net.logstash.logback", name = "logstash-logback-en logback-classic = { group = "ch.qos.logback", name = "logback-classic", version.ref = "logbackVersion" } jackson-databind = { group = "com.fasterxml.jackson.core", name = "jackson-databind", version.ref = "jacksonVersion" } postgres = { group = "org.postgresql", name = "postgresql", version.ref = "postgresVersion" } -kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit", version.ref = "kotlinVersion" } +kotlin-test = { group = "org.jetbrains.kotlin", name = "kotlin-test-junit5", version.ref = "kotlinVersion" } kompendium-core = { group = "io.bkbn", name = "kompendium-core", version.ref = "kompendiumVersion" } kotlinx-datetime = { group = "org.jetbrains.kotlinx", name = "kotlinx-datetime", version.ref = "kotlinxDatetimeVersion" } diff --git a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt similarity index 95% rename from src/intTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt rename to src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt index 7be5304b..bcafef31 100644 --- a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt +++ b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/InternalRouteTest.kt @@ -4,7 +4,7 @@ import io.ktor.client.request.* import io.ktor.http.* import io.ktor.server.testing.* import org.assertj.core.api.Assertions.assertThat -import org.junit.Test +import org.junit.jupiter.api.Test class InternalRouteTest : TestWithDb() { diff --git a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt similarity index 93% rename from src/intTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt rename to src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt index 89fa6779..e4fb16e6 100644 --- a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt +++ b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/TestWithDb.kt @@ -5,8 +5,8 @@ import io.ktor.client.plugins.contentnegotiation.* import io.ktor.serialization.kotlinx.json.* import io.ktor.server.config.* import io.ktor.server.testing.* -import org.junit.AfterClass -import org.junit.BeforeClass +import org.junit.jupiter.api.AfterAll +import org.junit.jupiter.api.BeforeAll import org.testcontainers.containers.PostgreSQLContainer abstract class TestWithDb { @@ -14,14 +14,14 @@ abstract class TestWithDb { companion object { private val postgresSQLContainer = PostgreSQLContainer("postgres:15-alpine") - @BeforeClass + @BeforeAll @JvmStatic fun setUp() { postgresSQLContainer.withDatabaseName("bygning") postgresSQLContainer.start() } - @AfterClass + @AfterAll @JvmStatic fun tearDown() { postgresSQLContainer.stop() diff --git a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt similarity index 97% rename from src/intTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt rename to src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt index 4632a05e..66ad9150 100644 --- a/src/intTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt +++ b/src/integrationTest/kotlin/no/kartverket/matrikkel/bygning/v1/BygningRouteTest.kt @@ -7,7 +7,7 @@ import io.ktor.server.testing.* import no.kartverket.matrikkel.bygning.TestWithDb import no.kartverket.matrikkel.bygning.models.Bygning import org.assertj.core.api.Assertions.assertThat -import org.junit.Test +import org.junit.jupiter.api.Test class BygningRouteTest : TestWithDb() {