Open nmck257 opened 5 days ago
Here's a couple of other cases that @MockBean
allowed.
Including mocks via additional config (not just other annotations):
@TestConfiguration
@MockBean({
MyServiceWithOutOfProcessSideEffectsOnBoot.class,
MyPreemptiveClientAuthTokenFetcher.class
})
@EnableSomething
@Import(OtherStuff.class)
public class SharedTestConfiguration { }
@SpringTestAnnotation
@Import({SharedTestConfiguration.class, SomeOtherConfig.class})
public class SomeTests {
If one of these mocks were autowired, stub behaviour could then be specified.
This doesn't work when returning a mock from a @Bean
method, depending on how beans are proxied:
@SpringTestAnnotation
@MockBean(MyServiceWithOutOfProcessSideEffectsOnBoot.class) // actually declared elsewhere
public class SomeTests {
@Autowired private MyServiceWithOutOfProcessSideEffectsOnBoot myService;
@Test
public void onlyThisTestSpecificallyWantsToStubIt() {
doReturn(true).when(myService).isSomething();
}
Can I take this issue to work on this
Hi @jack5505,
The team has not yet made a decision regarding this issue, and it's highly unlikely that the implementation would be performed by anyone outside the core team.
Thanks for the offer anyway.
MockitoBean
is designed to replace the now-deprecatedMockBean
annotation.MockBean
could target either a field or a type. Currently,MockitoBean
can only target a field. This issue proposes adding the support to target types toMockitoBean
, similar toMockBean
.(pasting some prose from #29917 comments)
Here's some Kotlin code to help demonstrate the point above:
vs