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
SpringExtension
andMockitoExtension
on the same test class, including support for@Captor
combined with@MockitoSpyBean
. - [x]
@MockitoBean
,@MockitoSpyBean
, and@TestBean
with@DirtiesContext
"before method" modes. - [x]
@MockitoBean
with JUnit 4 andSpringMethodRule
. - [x]
@MockitoBean
and@MockitoSpyBean
with@ContextHierarchy
. - [x]
@MockitoBean
and@MockitoSpyBean
with generics and parameterized types. - [x]
@MockitoBean
replacement of a bean with@Async
methods. - [x]
@MockitoBean
replacement of a scoped proxy. - [x]
@MockitoBean
replacement of a Spring AOP proxy. - [x]
@MockitoSpyBean
with circular dependencies. - [x] Spring AOP proxy that wraps a Mockito spy created via
@MockitoSpyBean
. - [x]
@MockitoSpyBean
on a field with generics can be used to replace an existing bean with matching generics that's produced by aFactoryBean
that's programmatically registered via anImportBeanDefinitionRegistrar
. - [x]
@MockitoBean
and@MockitoSpyBean
can select a single candidate bean to override when there are multiple candidates that match the required type: via an explicit bean name,@Qualifier
, or@Primary
on one of the candidate beans. - [x] Mock reset support for beans within the
ApplicationContext
configured 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.