You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This issue is currently being observed in version 3.4.3.
Here is quick bit of code to highlight issue
@SpringBootTestclassMockObjectTest {
@TestvoiddoNothing() {
// test started up fine
}
@TestConfigurationstaticclassInitMocks {
@MockBean// deprecated and set for removal in 3.6.0privateSomeObjectmockBean;
@MockitoBeanprivateSomeObjectmockitoBean;
@PostConstructpublicvoidinit() {
assertNotNull(mockBean); // successfulassertNotNull(mockitoBean); // fails
}
}
}
The text was updated successfully, but these errors were encountered:
@TestConfiguration is meta-annotated with @Component which is why this works with @MockBean. @MockitoBean doesn't support such injection. spring-projects/spring-framework#34415 has a suggestion for an alternative arrangement that may help.
Should the Javadoc be updated to reflect that MockitoBean is not a like-for-like replacement for the deprecated MockBean then?
Also @wilkinsona, I would need to verify but the suggestion in spring-projects/spring-framework#34415 would not work in scenarios where the TestConfiguration class has been introduced because the MockitoBean needs to be configured before usage by another Bean within the Spring context.
#43348 is tracking some documentation improvements.
the MockitoBean needs to be configured before usage by another Bean within the Spring context.
With that requirement, whether you're using @MockBean or @MockitoBean, we recommend using a @Bean method that creates, configures, and returns a Mockito mock directly instead.
This issue is currently being observed in version 3.4.3.
Here is quick bit of code to highlight issue
The text was updated successfully, but these errors were encountered: