Spring Boot Embedded PostgreSQL Database for Testing
In this story, we’ll learn how to implement Embedded PostgreSQL for Spring Boot Integration testing.
· Prerequisites
· Abstract
· Zonky Embedded Database
· Usage
∘ Maven Dependencies
∘ Writing Testing
· Conclusion
· References
Prerequisites
This is the list of all the prerequisites:
- Spring Boot 3+
- Maven 3.6.3
- Java 21
Abstract
Because of its lightweight nature, an embedded database can be useful during a project's development phase. Benefits include ease of configuration, quick startup time, testability, and the ability to rapidly evolve SQL during development.
Many Spring Boot projects use an H2 database or Docker container with TestContainers for integration testing. So, there are instances in which the project team desires to use an identical production database in testing without the need to execute a Docker container for some reason. This approach can have some advantages, such as speed of testing, performance, and the ability to reproduce production issues.