r/SpringBoot • u/Entire_Ad_9199 • Sep 05 '25
How-To/Tutorial Library for Spring Boot that makes Postgres-backed integration tests both fast and fully isolated
I build a small Spring Boot library that makes Postgres-backed integration tests both fast and fully isolated.
https://github.com/misirio/dbsandboxer
How it works:
At test-suite start-up it creates a single PostgreSQL template database.
For every JUnit test it runs CREATE DATABASE … TEMPLATE … to clone that template - about 50 ms per sandbox.
It plugs right into Spring Boot, Testcontainers, Flyway, and Liquibase.
If you use text fixtures you can mess with it freely, and never worry about affecting other tests.
I introduced this approach after hitting serious test-isolation problems on a large enterprise project. The approach worked greatly and the integration tests grow to past 4 000 tests without any slowdown or cleanup scripts.
I added an example project setup including test fixtures here: https://github.com/misirio/dbsandboxer/tree/main/examples/spring-boot-example
I would love to hear your feedback and how you solve this problem in your projects.
3
2
2
u/Sardonyx001 Sep 11 '25
Ive hit this exact same problem at my company excrpt we use Oracle. I really wanted to set up something similar so thanks for the project! I'll be forking this 🫡
7
u/wimdeblauwe Sep 05 '25
Interesting. I always use a JUnit extension now to clean up the database tables at the end of my `@SpringBootTest` tests.