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/sp...
I would love to hear your feedback and how you solve this problem in your projects.