|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||
@Retention(value=RUNTIME) @Target(value=FIELD) @Documented public @interface Spy
Allows shorthand wrapping of field instances in an spy object.
Example:
public class Test{
@Spy Foo spyOnFoo = new Foo();
@Before
public void init(){
MockitoAnnotations.initMocks(this);
}
...
}
Same as doing:
Foo spyOnFoo = Mockito.spy(new Foo());Warning if you call
MockitoAnnotations.initMocks(this) in a
super class constructor then this will not work. It is because fields
in subclass are only instantiated after super class constructor has returned.
It's better to use @Before.
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: REQUIRED | OPTIONAL | DETAIL: ELEMENT | |||||||||