Hello,

not sure if this is an spring issue or the mocking library that we are using, but below is a potential bug, and it could be related to https://github.com/spring-projects/spring-boot/issues/22566

When using MockBean or SpyBean in integration test, new application context is created for every Integration Test class. I am using Spring Boot version 3.0.4 with Kotlin.

I have created a sample application reproducing this issue here: https://github.com/kaushalsingh861/demo

when mock beans are commented, the application context is reused, when mock beans are used, it is causing new context to be created for every new IT class extending base IT class.

Comment From: kaushalsingh861

So it is happening even with Mockito, and java. I created a sample application here and used Mockito spybean https://github.com/kaushalsingh861/spybean

looks like https://github.com/spring-projects/spring-boot/issues/22566 is happening again

Comment From: wilkinsona

@kaushalsingh861 Looking at your latest sample, I would expect three application contexts to be created. This will happen because each test class has different spy configuration and, therefore, their contexts need to contain different beans. If you update the three test classes to have the same spies they will then share a single, cached context. In short, this is working as designed.