Scaling Integration Tests: Parallel Spring Tests with JUnit & Testcontainers
summary
Uses JUnit 5, Testcontainers and WireMock to run Spring Boot integration tests in parallel by reusing containers via a singleton container approach (static singletons or a JUnit extension), selectively enabling JUnit concurrency, and reusing Spring contexts. Calls out gotchas: Mockito mocks are not thread safe and avoid deleteAll/findAll and broad MockitoBean resets. On a real project with 12 test classes / 76 methods this cuts the test step from 46s to 22s while one stubborn test remains non-parallelizable.
AI-written summary · about
chapters (10)
- 0:00Introduction and motivation
- 1:39Reusing test containers
- 7:34Implementing singleton patterns
- 10:22Parallelizing JUnit tests
- 13:29Achieving test isolation
- 20:05Test isolation workflow
- 23:16Tooling for test stability
- 25:39Optimizing Spring contexts
- 30:09Summary and advanced tuning
- 37:50Questions and answers
related talks
44mFake It until You Make It! API Integration Testing with Containers & WireMock
13mImproving Integration Tests using Testcontainers
37mImproving Spring Boot test efficiency
15mTestcontainers: Simplify Your Integration Tests and Development
39mEasy Java Integrations Testing with Testcontainers
51mTestContainers: Integration Testing Without the Hassle
26mRemoving Complexity from Integration Tests Using Testcontainers
46mRemoving complexity from integration tests using Testcontainers!
