1

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?

3
  • The Spring test context framework uses threadlocals to manage the current TestContext if 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). Commented Nov 27, 2023 at 8:42
  • Yes, that's expected, but when I put @Isolated or set "junit.jupiter.execution.parallel.mode.classes.default =same_thread" - should not it be the single thread anyway? Commented Nov 27, 2023 at 9:03
  • Not sure if @Isolated would 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. Commented Nov 27, 2023 at 9:50

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.