In integration tests with spring application context I write quite often something like this in my configuration classes
@Bean
public MyComponent myComponent() {
return mock(MyComponent.class);
}
Sometimes I have to create those beans just to fulfill dependency requirements, sometimes I wire those mocks in my test to configure them.
In any case I'd love to get rid off those bean definitions. Is there a way to tell spring to create a mock of a type it is missing instead of throwing NoSuchBeanDefinitionException?
Have a look at spring-auto-mock.
By registering the AutoMockRegistryPostProcessor all the dependencies that Spring cannot find will be automagically converted to mockito mocks.
Here you have a test example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With