Spring Boot tests – assert max number of started Spring application contexts
I have multiple integration tests with @SpringBootTest
.
In some cases, Spring Boot starts multiple application contexts by executing these integration tests (e.g. due to usage of @MockBean
and @SpyBean
on specific test class instead of defining them on common abstract class), and it leads to increased build time or even worse – might crash surefire plugin execution (like in my case).
After identifying and fixing all those cases, now I have only two started application contexts (the first one is without any mocked beans and the second is with mock and spy beans).