@Retention(value=RUNTIME) @Target(value=FIELD) @Documented public @interface Spy
Example:
public class Test{ @Spy Foo spyOnFoo = new Foo(); @Before public void init(){ MockitoAnnotations.init(this); } ... }
Same as doing:
Foo spyOnFoo = Mockito.spy(new Foo());Warning if you call
MockitoAnnotations.init(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.Copyright © 2018. All rights reserved.