Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.


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.


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'
}

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}"