Overview
Over the past few weeks it has become apparent that our test suite does not fully cover all features of the Bean Override support in the TestContext framework.
To remedy that, we should introduce tests to cover corner cases and features that are currently not tested. As a starting point, we can adopt several of the tests for @MockBean and @SpyBean from Spring Boot's test suite.
Features to Test
The following is a list of features we should make sure we test before Spring Framework 6.2 GA.
- [x] Combining
SpringExtensionandMockitoExtensionon the same test class, including support for@Captorcombined with@MockitoSpyBean. - [x]
@MockitoBean,@MockitoSpyBean, and@TestBeanwith@DirtiesContext"before method" modes. - [x]
@MockitoBeanwith JUnit 4 andSpringMethodRule. - [x]
@MockitoBeanand@MockitoSpyBeanwith@ContextHierarchy. - [x]
@MockitoBeanand@MockitoSpyBeanwith generics and parameterized types. - [x]
@MockitoBeanreplacement of a bean with@Asyncmethods. - [x]
@MockitoBeanreplacement of a scoped proxy. - [x]
@MockitoBeanreplacement of a Spring AOP proxy. - [x]
@MockitoSpyBeanwith circular dependencies. - [x] Spring AOP proxy that wraps a Mockito spy created via
@MockitoSpyBean. - [x]
@MockitoSpyBeanon a field with generics can be used to replace an existing bean with matching generics that's produced by aFactoryBeanthat's programmatically registered via anImportBeanDefinitionRegistrar. - [x]
@MockitoBeanand@MockitoSpyBeancan select a single candidate bean to override when there are multiple candidates that match the required type: via an explicit bean name,@Qualifier, or@Primaryon one of the candidate beans. - [x] Mock reset support for beans within the
ApplicationContextconfigured viaMockReset.before()andMockReset.after().
Related Issues
- https://github.com/spring-projects/spring-boot/issues/22281
-
33743
-
33783
-
33811
-
33819
-
33829
Comment From: sbrannen
After porting numerous tests from Spring Boot's test suite and introducing additional tests (see Related Issues and linked commits above), I am closing this task with the hope that we now have better coverage of the supported features for Bean Overrides.