mockito test gives no such method error when run as junit test but when jars are added manually in run confugurations, it runs well

Try Cntrl + Shift + T on your eclipse screen. Check what are your results. Ideally eclipse should resolve this class only from one dependency. If you are getting multiple results, you may need to add exclusion on certain dependencies.

enter image description here

Also check if you are able to execute your test cases from command prompt. If you are able to do it, then it's not a maven problem. But if something is failing here, check your dependencies.


For me mockito version was creating issues. Just remove mockito dependency if you have added explicitly in your pom file. I just removed -

testCompile 'org.mockito:mockito-all:1.9.5' 

line from my gradle file. Lets power mock resolve and add mockito dependency it needs on it's own instead of you forcefully adding one which may led to conflict.

So for me dependencies are -

testCompile "org.powermock:powermock-module-junit4:1.6.4"
testCompile "org.powermock:powermock-module-junit4-rule:1.6.4" 
testCompile "org.powermock:powermock-api-mockito:1.6.4" 
testCompile "org.powermock:powermock-classloading-xstream:1.6.4" 

other than junit and other lib dependencies you may have.


I think there is an issue with Mockito version - I just updated the code from -

testCompile group: 'org.mockito', name: 'mockito-all', version: '1.8.5'

to

testCompile group: 'org.mockito', name: 'mockito-all', version: '1.10.19'