Skip to content

Spring Boot Test @SpyBean should be able to create a spy based on an interface class that is passed. #28903

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

Closed
teamfam2014 opened this issue Dec 3, 2021 · 6 comments
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement

Comments

@teamfam2014
Copy link

teamfam2014 commented Dec 3, 2021

I have created a stack overflow question regarding this enhancement here.

To summarize what was mentioned in that post above, I believe that we should be able to provide an interface class or an abstract class within the value of the @SpyBean annotation, and the framework should be intelligent enough to wrap the spring beans that extend the interface/abstract class with mockito spies. I was expecting this behaviour from the MockitoPostProcessor class.

Spring Boot Version: 2.2.8.RELEASE

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Dec 3, 2021
@wilkinsona
Copy link
Member

When @SpyBean is used on a field, we need a single bean to spy so that the field's value can be injected. See #7621, #10655, #11066, and #11077 where support for using @Primary to identify which bean to spy when there are multiple candidates.

When @SpyBean is used on a class, we have more freedom and I think it would be possible to allow a single class to identify multiple beans to spy upon. Looking back at the 1.x code, things appear to have been closer to this before @Primary support was added, although I'm not sure that it worked as described here.

I'll flag this one for a team meeting so that we can discuss if this is something that we want to support.

@wilkinsona wilkinsona added for: team-meeting An issue we'd like to discuss as a team to make progress type: enhancement A general enhancement labels Dec 6, 2021
@philwebb philwebb removed status: waiting-for-triage An issue we've not yet triaged for: team-meeting An issue we'd like to discuss as a team to make progress labels Dec 8, 2021
@philwebb philwebb added this to the 2.x milestone Dec 8, 2021
@Domineer-Long

This comment was marked as off-topic.

@philwebb philwebb modified the milestones: 2.x, 3.x Aug 19, 2022
@wilkinsona
Copy link
Member

@bclozel another one for Framework please to consider as a possible enhancement for @MockitoSpyBean.

@sbrannen
Copy link
Member

sbrannen commented Jun 1, 2024

@simonbasle, how does this relate to the current implementation of @MockitoSpyBean in Spring Framework?

@simonbasle
Copy link

@wilkinsona @sbrannen the bean override infrastructure in Framework is fields only

@wilkinsona
Copy link
Member

Thanks, @simonbasle. I assume that you're not considering expanding that support beyond fields so I'll close this one.

@wilkinsona wilkinsona closed this as not planned Won't fix, can't repro, duplicate, stale Jun 3, 2024
@wilkinsona wilkinsona removed this from the 3.x milestone Jun 3, 2024
@wilkinsona wilkinsona added the status: declined A suggestion or change that we don't feel we should currently apply label Jun 3, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined A suggestion or change that we don't feel we should currently apply type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

7 participants