Inject mock into a Spy

Skip to first unread message

deepak gupta

Dec 16, 2022, 1:51:04 AM12/16/22
to mockito
Hi There.

class A{
class B;
class C;

class C {
class D;
class E

I want to write unit test for class A:

I want C to be a spy so that I can call methods of C. I don't want to mock results of C's methods. However, I do want to mock D and E in C. How can I do this.

Some options I have explored are:
Option 1:
@Mock B b;
@Mock D d;
@Mock E e;

C c;

@InjectMocks A a;

@Mock B b;
@Mock D d;
@Mock E e;
@Spy C c = new C(d,e);
@InjectMocks A a;

None of the options are working for me. Please help.

Reply all
Reply to author
0 new messages