Automatic mock instantiation in a Spring JUnit test
Just in case anyone is still interested in this question, I have extended the code in the article mentioned by Yves Martin with inheritance, support for @Inject, etc... and created a Github project here: https://github.com/rinoto/spring-auto-mock
Here is a short article with a code example. A BeanDefinitionRegistryPostProcessor
implementation generates a mock object for each lacking bean definition. The generation part is done with a MocksFactory
, here is an example for such a factory.