We have 2 spring boot integration tests runnig on Netty.
We use gradle to run tests parallelly using flag: org.gradle.parallel=true
Test 1: @SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) creates org.springframework.boot.web.reactive.context.AnnotationConfigReactiveWebServerApplicationContext@3736a122
Test 2: @SpringBootTest(webEnvironment = WebEnvironment.MOCK) creates org.springframework.boot.web.reactive.context.GenericReactiveWebApplicationContext@45fa13a7
Two application contexts are created and one of the application contexts randomly is injected to production code and as a result we have two sets of beans.
The following dependencies are used:
dependencySet(group: 'org.springframework', version: '5.3.5')
dependencySet(group: 'org.springframework.boot', version: '2.4.4')
Is is ok behaviour, because in one case: mock web environment is used and in another real web environment?
ApplicationContextyou will run into issues. While the tests run in parallel they run in the same JVM and thus only 1 value for the static field can exist and basically the last one started will win. To fix don't use a class like that. - M. DeinumApplicationContextHolderin your code. At least judging from your description, else your question/problem isn't clear. Is it correct that there are 2 contexts created yes it. - M. Deinum