after upgrade to 2.7 ClassNotFoundException: org.mockito.exceptions.Reporter when run test

前端 未结 4 1537
孤独总比滥情好
孤独总比滥情好 2020-12-10 23:32

I try to set up junit, mokito and powermock together but when I ran a test I get ClassNotFoundException :(

testCompile \'junit:junit:4.12\'
testCompile \'org         


        
相关标签:
4条回答
  • 2020-12-11 00:10

    You should use PowerMock 1.7.+ (it's always better to use the last version), and also use powermock-api-mockito2 instead of powermock-api-mockito.

    testImplementation "org.powermock:powermock-api-mockito2:${versions.powermock}"
    
    0 讨论(0)
  • 2020-12-11 00:13

    That's what worked for me:

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:2.8.0'
    testCompile 'org.powermock:powermock-api-mockito2:1.7.0RC2'
    testCompile 'org.powermock:powermock-module-junit4:1.7.0'
    testCompile 'org.powermock:powermock-core:1.7.0'
    testCompile 'org.powermock:powermock-module-junit4-rule:1.7.0'
    

    using Mockito2 fixed the problem for me.

    0 讨论(0)
  • 2020-12-11 00:19

    PowerMock 1.6 isn't compatible with Mockito 2.7 (take a look at https://github.com/powermock/powermock/wiki/Mockito#supported-versions)

    You should use PowerMock 1.7.0RC2 (or 1.7.0RC3 if 1.7.0RC2 doesn't work), and also use powermock-api-mockito2 instead of powermock-api-mockito.

    0 讨论(0)
  • 2020-12-11 00:19

    I'm using Kotlin 1.2.61/mockito 2.15 and powermock 1.7.0RC2 DID NOT work me. The set of dependencies that did the trick for me is:

    dependencies {
        testImplementation "junit:junit:4.12"
        testImplementation "org.mockito:mockito-core:2.15.0"
        testImplementation "io.kotlintest:kotlintest:2.0.7"
        testImplementation 'org.powermock:powermock-module-junit4-rule:2.0.0-beta.5'
        testImplementation 'org.powermock:powermock-core:2.0.0-beta.5'
        testImplementation 'org.powermock:powermock-module-junit4:2.0.0-beta.5'
        testImplementation 'org.powermock:powermock-api-mockito2:2.0.0-beta.5'
    }
    
    0 讨论(0)
提交回复
热议问题