And here is my code.
public class SpyTest {
public String test(String name){
System.out.println("only show when it doesn't beening mocked");
return name;
}
}
testcase
@Test
public void testSpy(){
SpyTest spyTest = new SpyTest();
//mock
SpyTest mock = Mockito.mock(spyTest.getClass());
Mockito.when(mock.test("Tom")).thenReturn("not Tom");
System.out.println(mock.test("Tom"));
//spy
SpyTest spy = Mockito.spy(spyTest);
Mockito.when(spy.test("Tom")).thenReturn("not Tom");
System.out.println(spy.test("Tom"));
}
here is the result
not Tom
only show when it doesn't beening mocked
not Tom
Is there any way could i make the real method I spied not execute?
在 2012年3月10日星期六UTC+8上午5时00分25秒,Brice写道: