Using JMockit to mock autowired interface implementations

前端 未结 5 502
暖寄归人
暖寄归人 2020-12-17 18:10

We are writing JUnit tests for a class that uses Spring autowiring to inject a dependency which is some instance of an interface. Since the class under test never explicitly

5条回答
  •  春和景丽
    2020-12-17 18:41

    For those people who met

    java.lang.IllegalStateException: Missing @Injectable for field *** 
    

    or

    java.lang.IllegalStateException: Missing @Tested class for field ***
    

    error when using jmockit to mock @autowired field in spring ( or spring boot) framework, I did below two steps to avoid above errors:

    1. use @Tested(fullyInitialized=true) instead of @Tested

    https://groups.google.com/forum/#!msg/jmockit-users/uo0S51lSX24/lQhLNN--eJcJ

    1. revert jmockit's version back to 1.18 or previous ones

    https://groups.google.com/forum/#!topic/jmockit-users/wMFZggsA8LM

提交回复
热议问题