From 903ed9988ee88c179224f458b6e0849c12c81a25 Mon Sep 17 00:00:00 2001 From: Cursor Agent Date: Wed, 14 Jan 2026 10:57:18 +0000 Subject: [PATCH] Fix tests by using H2 and disabling Flyway Run Spring context tests without requiring a local Postgres instance by activating a test profile backed by in-memory H2 and skipping Flyway migrations. Co-authored-by: wasif.sarwar9 --- backend/build.gradle.kts | 1 + .../backend/BackendApplicationTests.java | 2 ++ .../resources/application-test.properties | 21 +++++++++++++++++++ 3 files changed, 24 insertions(+) create mode 100644 backend/src/test/resources/application-test.properties diff --git a/backend/build.gradle.kts b/backend/build.gradle.kts index 04d6745..375b315 100644 --- a/backend/build.gradle.kts +++ b/backend/build.gradle.kts @@ -38,6 +38,7 @@ dependencies { annotationProcessor("org.projectlombok:lombok") testImplementation("org.springframework.boot:spring-boot-starter-test") testImplementation("org.springframework.security:spring-security-test") + testRuntimeOnly("com.h2database:h2") testRuntimeOnly("org.junit.platform:junit-platform-launcher") } diff --git a/backend/src/test/java/com/pennywise/backend/BackendApplicationTests.java b/backend/src/test/java/com/pennywise/backend/BackendApplicationTests.java index a583525..f5df791 100644 --- a/backend/src/test/java/com/pennywise/backend/BackendApplicationTests.java +++ b/backend/src/test/java/com/pennywise/backend/BackendApplicationTests.java @@ -2,8 +2,10 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; @SpringBootTest +@ActiveProfiles("test") class BackendApplicationTests { @Test diff --git a/backend/src/test/resources/application-test.properties b/backend/src/test/resources/application-test.properties new file mode 100644 index 0000000..bff34c7 --- /dev/null +++ b/backend/src/test/resources/application-test.properties @@ -0,0 +1,21 @@ +spring.application.name=pennywise + +# =============================== +# DATABASE (tests) +# =============================== +spring.datasource.url=jdbc:h2:mem:pennywise_test;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;DB_CLOSE_ON_EXIT=FALSE +spring.datasource.username=sa +spring.datasource.password= +spring.datasource.driver-class-name=org.h2.Driver + +# =============================== +# JPA / HIBERNATE (tests) +# =============================== +spring.jpa.hibernate.ddl-auto=create-drop +spring.jpa.show-sql=false + +# =============================== +# FLYWAY (tests) +# =============================== +spring.flyway.enabled=false +