Injecting Mockito Mock objects using Spring JavaConfig and @Autowired

前端 未结 3 1248
执笔经年
执笔经年 2021-02-07 22:39

I\'m trying to replace an @Autowired object with a Mockito mock object. The usual way of doing this was with xml using Springockito:



        
3条回答
  •  南旧
    南旧 (楼主)
    2021-02-07 22:51

    It appears that SpringockitoContextLoader extends GenericXmlContextLoader which is described as:

    Concrete implementation of AbstractGenericContextLoader that reads bean definitions from XML resources.

    So you are limited to xml bean definitions at the moment.

    You could write your own context loader, taking relevant parts from the SpringockitoContextLoader class. Take a look here to get started, perhaps you could extend AnnotationConfigContextLoader for example?

提交回复
热议问题