Mockito when().thenReturn calls the method unnecessarily

后端 未结 5 2324
挽巷
挽巷 2021-02-19 02:23

I\'m working a bit on an inherited code. I\'ve written a test that is supposed to catch NullPointerException (for it is trying to call a method from null object)



        
5条回答
  •  礼貌的吻别
    2021-02-19 02:46

    This may help others who use annotations. If you are using annotations, may be you need to use @Mock instead of @InjectMocks. Because @InjectMocks works as @Spy and @Mock together. And @Spy keeps track of recently executed methods and you may feel that incorrect data is returned/subbed. Check these two:

    https://groups.google.com/forum/?fromgroups#!topic/mockito/9WUvkhZUy90

    http://code.google.com/p/mockito/issues/detail?id=127

提交回复
热议问题