Cross-posting from Stackoverflow, where I had the same question but did not get a conclusive answer.

I have a spring boot app and have written unit tests using a postgres test container (https://www.testcontainers.org/) and JUnit. The tests have the @SpringBootTest annotation which loads the context and starts up a test container before running the test.

Loading the context and starting the container takes around 15sec on my relatively old Macbook, but the test themselves are pretty fast (< 100ms each). So in a full build with 100s of tests, this does not really matter. It is a one time cost of 15sec. But developing/debugging the tests individually in an IDE becomes very slow. Every single test incurs a 15 sec startup cost.

I know IntelliJ and Springboot support hot reload of classes when the app is running. Can the same be done for unittests. i.e Keep the context loaded and the testcontainer(DB) running but recompile just the modified test class and run the selected test again . Essentially keep the JVM running and reload the edited test class.

Comment From: wilkinsona

Thanks for the suggestion, but it's beyond the scope of Spring Boot. With Devtools there's a single entry point into the application (its main method) but this isn't the case with unit tests. When running unit tests the entry point varies depending on the IDE, and to some extent, the test framework that's being used. The IDE would have to know to keep the JVM that is running the tests alive and to expect multiple results for a given test or set of tests as changes are detected and the tests re-run. In short, this would have to be an IDE and possibly test framework feature rather than a Spring Boot feature. Thanks again for the suggestion in any case.