June 11, 2024

Replace H2 with a real database in spring boot application

Springboot application facing bellow error or need to implement real test data base:

Senario:

Could not prepare statement [Table “XXXX” not found (this database is empty); SQL statement

Solution:

Add bellow configuration in test application.yml
spring:
 test: 
  database:
       replace: none

---

Code:

@DataJpaTest @TestPropertySource(properties = { "spring.test.database.replace=none", "spring.datasource.url=jdbc:tc:postgresql:16-alpine:///db" //Need to update based on the database })

Plugins:

testImplementation("org.springframework.boot:spring-boot-testcontainers")
testImplementation("org.testcontainers:junit-jupiter")
testImplementation("org.testcontainers:mariadb")

Test containers:

 https://testcontainers.com/






References:

test container examples here


No comments:

Post a Comment

I'm certainly not an expert, but I'll try my hardest to explain what I do know and research what I don't know.

My Favorite Site's List

#update below script more than 500 posts