rysang / mockito

Automatically exported from code.google.com/p/mockito
0 stars 0 forks source link

Can not inject Spy injected with @InjectMocks #450

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

@Mock
A a;

@InjectMocks
@Spy
B b; // B has a member of type A

@InjectMocks
C c; // C has a member of type B

What is the expected output? 
a should be injected into b.
b should be injected into c.

What do you see instead?
a is being injected into b.
b IS NOT being injected into c

What version of the product are you using? On what operating system?
Mockito version: 1.9.5
SO: Windows 7

Additional note: If I delete @InjectMocks from b, b is injected into c.

Original issue reported on code.google.com by jag...@gmail.com on 11 Sep 2013 at 7:36

GoogleCodeExporter commented 8 years ago
Your injection maybe be too complex for Mockito. Mockito is not a full featured 
dependency injection framework, it merely minimize work for simple and 
boilerplate DI code. And it doesn't intend to.

Your case shows a complex code to set up that seems to go beyond what should be 
done in a Unit Test, either that's a sign that either the production code or 
the test code needs to be redesigned in order to gain a better testability.

So we won't update the mockito injection code to support deep injection graph.

Cheers
Brice

Original comment by brice.du...@gmail.com on 4 Dec 2013 at 1:45