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 index b4c8158..bff34c7 100644 --- a/backend/src/test/resources/application-test.properties +++ b/backend/src/test/resources/application-test.properties @@ -1,28 +1,21 @@ -# Test configuration -spring.application.name=pennywise-test +spring.application.name=pennywise -# Database - Uses environment variables from CI or defaults for local testing -spring.datasource.url=${SPRING_DATASOURCE_URL:jdbc:postgresql://localhost:5432/pennywise_test} -spring.datasource.username=${SPRING_DATASOURCE_USERNAME:pennywise} -spring.datasource.password=${SPRING_DATASOURCE_PASSWORD:pennywise} -spring.datasource.driver-class-name=org.postgresql.Driver +# =============================== +# 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 -spring.jpa.hibernate.ddl-auto=none +# =============================== +# JPA / HIBERNATE (tests) +# =============================== +spring.jpa.hibernate.ddl-auto=create-drop spring.jpa.show-sql=false -# Flyway -spring.flyway.enabled=true -spring.flyway.locations=classpath:db/migration -spring.flyway.baseline-on-migrate=true -spring.flyway.clean-disabled=false - -# Logging - reduce noise in tests -logging.level.root=WARN -logging.level.com.pennywise=INFO -logging.level.org.springframework.security=WARN - -# Security - disable for tests -spring.security.user.name=test -spring.security.user.password=test +# =============================== +# FLYWAY (tests) +# =============================== +spring.flyway.enabled=false