Try something like this:
import org.junit.*; import mockit.*; public class ATest { @Tested A a; @Injectable B b; @Test public void testMethod() { a.method(); new Verifications() {{ b.callMethodInB(); }}; } }
JMockit automatically creates A with an injected instance of B (from fake field B ), setting it to field A in the test class. This is independent of the DI framework used (Spring).
source share