-
Notifications
You must be signed in to change notification settings - Fork 38.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Introduce missing tests for Bean Override features #33742
Comments
sbrannen
added a commit
that referenced
this issue
Oct 18, 2024
sbrannen
added a commit
that referenced
this issue
Oct 18, 2024
sbrannen
added a commit
that referenced
this issue
Oct 18, 2024
sbrannen
added a commit
that referenced
this issue
Oct 18, 2024
sbrannen
added a commit
that referenced
this issue
Oct 18, 2024
sbrannen
added a commit
that referenced
this issue
Oct 23, 2024
Use cases not yet supported with @MockitoSpyBean are currently @Disabled. See gh-33742
sbrannen
added a commit
that referenced
this issue
Oct 24, 2024
sbrannen
added a commit
that referenced
this issue
Oct 24, 2024
sbrannen
added a commit
that referenced
this issue
Oct 24, 2024
sbrannen
added a commit
that referenced
this issue
Oct 24, 2024
sbrannen
added a commit
that referenced
this issue
Oct 29, 2024
This commit introduces a test which verifies that @MockitoSpyBean on a field with generics can be used to replace an existing bean with matching generics that's produced by a FactoryBean that's programmatically registered via an ImportBeanDefinitionRegistrar. However, the test is currently @Disabled until the fix for spring-projects/spring-boot#40234 has been ported to Spring Framework. See gh-33742
sbrannen
added a commit
that referenced
this issue
Oct 30, 2024
This commit introduces integration tests which verify that Bean Overrides (for example, @MockitoBean and @MockitoSpyBean) can select a single candidate bean to override when there are multiple candidates that match the required type. To "select" the desired bean, these tests rely on one of the following. - explicit bean name in the bean override annotation - explicit @Qualifier on the bean override field - explicit @Primary on one of the candidate beans However, the @Primary tests are currently @Disabled until @Primary is honored in the Spring TestContext Framework. See gh-33742
sbrannen
added a commit
that referenced
this issue
Oct 30, 2024
This commit verifies that MockReset.before() and MockReset.after() are supported for beans within the ApplicationContext. However, the test class must declare a field annotated with either @MockitoBean or @MockitoSpyBean in order for the MockReset feature to be triggered. See gh-33742
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. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
SpringExtension
andMockitoExtension
on the same test class, including support for@Captor
combined with@MockitoSpyBean
.@MockitoBean
,@MockitoSpyBean
, and@TestBean
with@DirtiesContext
"before method" modes.@MockitoBean
with JUnit 4 andSpringMethodRule
.@MockitoBean
and@MockitoSpyBean
with@ContextHierarchy
.@MockitoBean
and@MockitoSpyBean
with generics and parameterized types.@MockitoBean
replacement of a bean with@Async
methods.@MockitoBean
replacement of a scoped proxy.@MockitoBean
replacement of a Spring AOP proxy.@MockitoSpyBean
with circular dependencies.@MockitoSpyBean
.@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
.@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.ApplicationContext
configured viaMockReset.before()
andMockReset.after()
.Related Issues
@MockitoBean
and@MockitoSpyBean
make it easier to inject any underlying proxy target as well as the mock or spy #33743@MockitoBean
,@MockitoSpyBean
, &@TestBean
do not work with@DirtiesContext
"before method" modes #33783FactoryBean
with generics #33811@Primary
semantics #33819MockReset
should be honored without@Mockito[Spy]Bean
fields #33829The text was updated successfully, but these errors were encountered: