From 7fc19b5bbe67068b5d6db0e86ceaaf74eb23d91c Mon Sep 17 00:00:00 2001 From: Jan Klattenhoff Date: Wed, 25 Sep 2024 10:06:45 +0200 Subject: [PATCH] test: Add H2 database for testing and update config --- .gitea/workflows/qs.yml | 14 -------------- build.gradle.kts | 8 ++++++++ src/main/resources/application-test.properties | 5 +++++ src/test/java/application-test.properties | 0 .../lf8_starter/Lf8StarterApplicationTests.java | 1 + 5 files changed, 14 insertions(+), 14 deletions(-) create mode 100644 src/main/resources/application-test.properties create mode 100644 src/test/java/application-test.properties diff --git a/.gitea/workflows/qs.yml b/.gitea/workflows/qs.yml index 8efeaa2..43fcf81 100644 --- a/.gitea/workflows/qs.yml +++ b/.gitea/workflows/qs.yml @@ -9,20 +9,6 @@ jobs: runs-on: "ubuntu-latest" container: image: "cimg/openjdk:21.0-node" - services: - postgres: - image: postgres:16.4 - env: - POSTGRES_DB: lf8_starter_db - POSTGRES_USER: lf8_starter - POSTGRES_PASSWORD: secret - ports: - - 5432:5432 - options: >- - --health-cmd="pg_isready -U lf8_starter" - --health-interval=10s - --health-timeout=5s - --health-retries=3 steps: - name: "Checkout" uses: actions/checkout@v3 diff --git a/build.gradle.kts b/build.gradle.kts index e9345bc..3bc0350 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -7,6 +7,13 @@ plugins { group = "de.szut" version = "0.0.1-SNAPSHOT" +tasks.test { + useJUnitPlatform() + + // Activate the 'test' profile for Spring during tests + systemProperty("spring.profiles.active", "test") +} + java { toolchain { languageVersion = JavaLanguageVersion.of(21) @@ -35,6 +42,7 @@ dependencies { implementation("org.springframework.boot:spring-boot-starter-oauth2-client:3.3.4") runtimeOnly("org.postgresql:postgresql") implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.6.0") + testImplementation("com.h2database:h2") } tasks.withType { diff --git a/src/main/resources/application-test.properties b/src/main/resources/application-test.properties new file mode 100644 index 0000000..af21e0e --- /dev/null +++ b/src/main/resources/application-test.properties @@ -0,0 +1,5 @@ +spring.datasource.url=jdbc:h2:mem:testdb;DB_CLOSE_DELAY=-1 +spring.datasource.driver-class-name=org.h2.Driver +spring.datasource.username=sa +spring.datasource.password= +spring.jpa.database-platform=org.hibernate.dialect.H2Dialect \ No newline at end of file diff --git a/src/test/java/application-test.properties b/src/test/java/application-test.properties new file mode 100644 index 0000000..e69de29 diff --git a/src/test/java/de/szut/lf8_starter/Lf8StarterApplicationTests.java b/src/test/java/de/szut/lf8_starter/Lf8StarterApplicationTests.java index 942f2cb..b5c7f7b 100644 --- a/src/test/java/de/szut/lf8_starter/Lf8StarterApplicationTests.java +++ b/src/test/java/de/szut/lf8_starter/Lf8StarterApplicationTests.java @@ -2,6 +2,7 @@ package de.szut.lf8_starter; import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.TestPropertySource; @SpringBootTest class Lf8StarterApplicationTests {