-
Notifications
You must be signed in to change notification settings - Fork 38.4k
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
Bean overriding in tests should use by-type semantic if no name is specified #32761
Comments
@MockitoSpyBean
is required to use bean name
@MockitoSpyBean
is required to use bean name
See also #32760. It looks like bean overriding does not work with a by-type semantic. While that's a choice we can make, it looks like the Mockito support in Spring Boot does do that. If I haven't overlooked anything, this seems to me a too intrusive change of behavior for people moving from the Spring Boot support, so we should support that as well IMO. |
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
Note that in the second case ( I've started making modifications to override based on type by default, but I need to clarify what should happen in the case where multiple candidates are found when looking up that way. |
I am wondering why we wouldn’t consider what Spring Boot does for a start. The algorithm looks straightforward enough to me, with the addition of the qualifier in the metadata. |
I will follow up in another issue for M3 (#32822) to introduce the option of also using qualifiers. |
Environment: Spring 6.2.0-M1, Java 21
Example project: https://github.com/hantsy/spring6-sandbox/tree/master/test-bean
I tried to write a test to experience the new
@MockitoSpyBean
.I tried to use
customerServiceSpy
as the field name here, but it does not work. I have to usecustomerSerivce
here and set the bean name attribute.Whereas, in the test that's testing
@MockitoBean
inCustomerServiceMockitoTest
, usingcustomerServiceMock
(no need set the bean name) worked well.The spied field name should be named by developers freely, and the spied bean should override the real bean by type (not name) firstly.
The text was updated successfully, but these errors were encountered: