So I\'ve been struggling pretty much all day trying to get Mockito to work for my Android project. I added everything to my Gradle build file:
androidTestCom
Use mockito-android instead of mockti-core for instrumentation tests.
For me it helped to use newest dexmaker (and remove all other powermock/mockito dependencies):
androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
For me it helped switching from mockito to powermock. Downgrading mockito to 1.x gave me the null exception, updgrading to 2.x gave me the AbstractMethodError. Just include in dependencies (instead of mockito):
testCompile "org.powermock:powermock-module-junit4:1.6.5"
testCompile "org.powermock:powermock-module-junit4-rule:1.6.5"
testCompile "org.powermock:powermock-api-mockito:1.6.5"
testCompile "org.powermock:powermock-classloading-xstream:1.6.5"
Dexmaker does not support Mockito 2.0 since the definition of MockMaker
has changed. I suggest you use Mockito 1.10.19 but then you will run into this NPE for which I have submitted a fix.
Looks like my fix is now merged into dexmaker as of version 1.5
Mockito.initAnnotations
and @RunWith
are incompatible to each other. They both initialize the annotations. Try to remove one of the two. I suggested to keep the runner.