Improving Spring Boot test efficiency
summary
Spring Integration Test contexts are cached by a merged configuration key, causing many simultaneous heavy contexts (TestContainers-managed Docker containers, thread pools) and a CI host to hit OOM after ~25 minutes with ~120 containers. Practical fixes: set spring.test.context.cache.maxSize (try 4 or 1), use static singleton docker containers with overridden destroy, lazy-initialize datasources, prebuild DB images (Mirror’s persistence-tooling), and reorder tests plus eagerly close contexts via a small library — results: far fewer active containers and up to ~2x or 30% faster suites.
AI-written summary · about
chapters (17)
- 0:00Introduction
- 3:46Spring test inefficiencies
- 9:57Optimization goals
- 11:01@DirtiesContext and cache
- 13:49Unique test configs
- 15:16Docker singletons
- 16:43Pre-applying DB migrations
- 17:48Lazy data sources
- 19:14Dynamic ports
- 21:46Thread pool shutdown
- 22:50Test reordering
- 26:49Results and impact
- 28:59Context management benefits
- 31:03Open-source library
- 33:13Small vs large projects
- 34:41Test infrastructure
- 35:03Key takeaways
related talks
48mCaching the Spring Context in Tests: How to Speed Up Testing
41mIntegration Testing with Spring
45mSpring Boot Test - A look behind the curtain
01h 40mSpringOne Keynote: Accelerating Innovation with Spring
01h 03mBootiful Spring Boot 3
48mTesting Spring Boot Applications Demystified
01h 13mSpring: Your next Java microframework
49mBuilding Lean Spring Boot Applications for the Cloud
