spring-boot icon indicating copy to clipboard operation
spring-boot copied to clipboard

Deprecate @MockBean and @SpyBean

Open wanger26 opened this issue 1 year ago • 6 comments

Change Summary

  • Deprecate Deprecate @MockBean and @SpyBean in favor of Spring Framekworks 6.2.0 @MockitoBean and @MockitoSpy. See https://github.com/spring-projects/spring-framework/commit/e1bbdf09139dca7c21ec64e140bcc3bda463b2f6
  • Migrate usages of @MockBean and @SpyBean to @MockitoBean an d @MockitoSpy

Issue

  • https://github.com/spring-projects/spring-boot/issues/39860

wanger26 avatar Mar 10 '24 23:03 wanger26

FTR, I am maintaining a branch of the changes required to upgrade to SF 6.2.0-SNAPSHOT and some of the changes in this PR are already applied there, which I intend to submit once Spring Boot is ready to build against it.

snicoll avatar Mar 11 '24 10:03 snicoll

Closing PR /draft based on comments above.

wanger26 avatar Mar 11 '24 17:03 wanger26

@wanger26 Can we keep this one? It's likely that @snicoll won't migrate the existing tests and the work you've done here looks valuable for us.

philwebb avatar Mar 11 '24 17:03 philwebb

Sounds good, that is no problem 👍

wanger26 avatar Mar 11 '24 23:03 wanger26

Here is what's needed so far to get a green build with Spring Framework 6.2.0-SNAPSHOT: https://github.com/snicoll/spring-boot/tree/compat-6.2.x

Regarding Mockito support, I had to remove the automatic intialization of mocks as the support in the core framework does that now and they were trumping each other. Given that the support is going to be deprecated, tests should still use the existing infrastructure, rather than moving to the new annotations. It's a different story for smoke tests & co though.

snicoll avatar Mar 12 '24 07:03 snicoll

Here is what's needed so far to get a green build with Spring Framework 6.2.0-SNAPSHOT: https://github.com/snicoll/spring-boot/tree/compat-6.2.x

Regarding Mockito support, I had to remove the automatic intialization of mocks as the support in the core framework does that now and they were trumping each other. Given that the support is going to be deprecated, tests should still use the existing infrastructure, rather than moving to the new annotations. It's a different story for smoke tests & co though.

Should we leave all tests using the Mockito outside of smoke tests and co untouched, or should we only leave the unit tests for the Mockito support untouched?

wanger26 avatar Mar 12 '24 23:03 wanger26

Thank you, @wanger26.

wilkinsona avatar Jul 12 '24 13:07 wilkinsona