-
Notifications
You must be signed in to change notification settings - Fork 40.9k
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
Deprecate @MockBean and @SpyBean #39860
Comments
@philwebb do we want to target release 2.3.0 with this change? Also are we thinking of marking those for removal at this time? |
We'll probably look at this in Spring Boot 3.4.0 which will be the first release to build on Spring Framework 6.2. I'm not sure yet about when well mark the existing annotations for removal. |
Okay sounds good. I can take this one on. Do we want to take this opportunity to migrate our own usages of those two annotations over to the new spring framework ones? |
… classes - Deprecate Deprecate @MockBean and @SpyBean in favor of Spring Framekworks 6.2.0 @MockitoBean and @MockitoSpy. See spring-projects/spring-framework@e1bbdf0 - Migrate usages of @MockBean and @SpyBean to @MockitoBean an d @MockitoSpy spring-projects#39860 Signed-off-by: Jakob Wanger <[email protected]>
- Deprecate Deprecate @MockBean and @SpyBean in favor of Spring Framekworks 6.2.0 @MockitoBean and @MockitoSpy. See spring-projects/spring-framework@e1bbdf0 - Migrate usages of @MockBean and @SpyBean to @MockitoBean an d @MockitoSpy spring-projects#39860 Signed-off-by: Jakob Wanger <[email protected]>
What is the replacement for @TestConfiguration
@Import({ /* some config shared by tests */ })
@MockBean({ /* some beans that need to be mocked in shared tests */ })
public class SharedWebTestConfig {
// ...
}
@WebMvcTest(SomeController.class)
@Import(SharedWebTestConfig.class)
public class SomeTetsts {
// ...
} Now the only solution is to make the mock beans manually? @TestConfiguration
@Import({ /* some config shared by tests */ })
public class SharedWebTestConfig {
@Bean
public BeanClass myBean() {
return Mockito.mock(BeanClass.class);
}
// ...
} |
I don't believe Framework has a direct equivalent although you don't have to resort to declaring the mock beans manually. You can use |
What Andy said is correct: Spring Framework does not support |
Thanks for the confirmation. The trouble with using inheritance is that you can only do it once, while all the annotation-driven config is composable. The |
fyi @OrangeDog, other readers -- I've opened a standalone issue in Spring Framework for this topic: |
With spring-projects/spring-framework#29917 fixed we should consider deprecating our versions.
The text was updated successfully, but these errors were encountered: