-
Couldn't load subscription status.
- Fork 38.8k
Closed
Labels
Milestone
Description
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.
- Combining
SpringExtensionandMockitoExtensionon the same test class, including support for@Captorcombined with@MockitoSpyBean. -
@MockitoBean,@MockitoSpyBean, and@TestBeanwith@DirtiesContext"before method" modes. -
@MockitoBeanwith JUnit 4 andSpringMethodRule. -
@MockitoBeanand@MockitoSpyBeanwith@ContextHierarchy. -
@MockitoBeanand@MockitoSpyBeanwith generics and parameterized types. -
@MockitoBeanreplacement of a bean with@Asyncmethods. -
@MockitoBeanreplacement of a scoped proxy. -
@MockitoBeanreplacement of a Spring AOP proxy. -
@MockitoSpyBeanwith circular dependencies. - Spring AOP proxy that wraps a Mockito spy created via
@MockitoSpyBean. -
@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. -
@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. - Mock reset support for beans within the
ApplicationContextconfigured viaMockReset.before()andMockReset.after().
Related Issues
- Recommend the use of AopTestUtils.getTargetObject() when setting expectations on a spied bean that Spring has proxied spring-boot#22281
- When using
@MockitoBeanand@MockitoSpyBeanmake it easier to inject any underlying proxy target as well as the mock or spy #33743 @MockitoBean,@MockitoSpyBean, &@TestBeando not work with@DirtiesContext"before method" modes #33783- Bean Overrides cannot reliably override beans created by a
FactoryBeanwith generics #33811 - Test Bean Overrides do not honor
@Primarysemantics #33819 MockResetshould be honored without@Mockito[Spy]Beanfields #33829
JKatzwinkel