I tried Junit 5.3 parallel execution for Spring Boot (2.7.12) integration tests.
junit.jupiter.execution.parallel.enabled = true
junit.jupiter.execution.parallel.mode.default = same_thread
junit.jupiter.execution.parallel.mode.classes.default = concurrent
The execution time for tests increased, and by the logs I see that Spring application is initiated more frequently (it looks like the context is not cached/reused).
I tried to runs all the classes in the same thread (by putting same_thread), using annotations @Execution(ExecutionMode.SAME_THREAD) and @Isolated over test classes, but it did not help - the context is initiated each time for a new class.
The only thing that helps is setting junit.jupiter.execution.parallel.enabled back to false.
Is there any ability to reuse Spring Application context for junit tests run in parallel?
TestContextif threads get reused or multiple threads operate on the same context configuration it might see multiple cache misses leading to multiple instantiations of 1 configuration combination, leading to it being loaded multiple times (eventually it will be cached but it will take more time).@Isolatedwould help. Not garantueed. The classes will run now in sequence but the actual tests in the class can use a different thread (not seeing the set thread-local). I'm not sure if parallel execution and stateful tests (as that is what they are) are a good fit.