Mocking two objects of the same type with Mockito

前端 未结 3 588
孤城傲影
孤城傲影 2020-12-20 12:58

I\'m writing unit tests using Mockito and I\'m having problems mocking the injected classes. The problem is that two of the injected classes are the same type, and only diff

3条回答
  •  暖寄归人
    2020-12-20 13:40

    Just confirmed what Splonk pointed out and it works that way in Mockito 1.9.5, as soon as I removed one of the mocked classes, it failed.

    So, in your case, make sure you have both of the mocked classes with the same name as in the class in your test:

    @Mock
    private SomeClass someClassA;
    @Mock
    private SomeClass someClassB;
    

提交回复
热议问题