Mockito AbstractMethodError on initMocks

前端 未结 5 1389
长发绾君心
长发绾君心 2020-12-17 17:16

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         


        
相关标签:
5条回答
  • 2020-12-17 17:48

    Use mockito-android instead of mockti-core for instrumentation tests.

    0 讨论(0)
  • 2020-12-17 17:52

    For me it helped to use newest dexmaker (and remove all other powermock/mockito dependencies):

        androidTestCompile 'com.linkedin.dexmaker:dexmaker-mockito:2.2.0'
    
    0 讨论(0)
  • 2020-12-17 17:56

    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"
    
    0 讨论(0)
  • 2020-12-17 18:03

    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

    0 讨论(0)
  • 2020-12-17 18:14

    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.

    0 讨论(0)
提交回复
热议问题