I am trying to test my android project by Mockito.
But it seems that spy does not work as I think. Isn't a spy object is equal to a real object?
when I try to call a method of spy object, testing result alway is AbstractMethodError(just as follows).
java.lang.AbstractMethodError: abstract method not implemented
at com.google.dexmaker.mockito.InvocationHandlerAdapter$ProxiedMethod.isAbstract(InvocationHandlerAdapter.java)
at org.mockito.internal.invocation.InvocationImpl.callRealMethod(InvocationImpl.java:109)
at org.mockito.internal.stubbing.answers.CallsRealMethods.answer(CallsRealMethods.java:41)
at org.mockito.internal.handler.MockHandlerImpl.handle(MockHandlerImpl.java:93)
at org.mockito.internal.handler.NullResultGuardian.handle(NullResultGuardian.java:29)
at org.mockito.internal.handler.InvocationNotifierHandler.handle(InvocationNotifierHandler.java:38)
at com.google.dexmaker.mockito.InvocationHandlerAdapter.invoke(InvocationHandlerAdapter.java:49)
at ArrayList_Proxy.add(ArrayList_Proxy.generated)
My test case:
public void testGetAllCountryKeywords_WithSpy(){
List<String> list = new ArrayList<>();
List spy = spy(list);
spy.add("hi");
}
Here is the dependencies in my build.gradle.
dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile 'junit:junit:4.12'
androidTestCompile "com.google.dexmaker:dexmaker:1.+"
androidTestCompile "com.google.dexmaker:dexmaker-mockito:1.+"
androidTestCompile 'org.mockito:mockito-core:1.10.+'
androidTestCompile 'com.android.support.test:runner:0.3'
}
Can someone give me some suggestion? I really have no idea. Thanks!