Reputation: 41
I've been working on some tests that have complex static methods, so I'm using powermock to mock them in my tests.
My config was
Everything worked fine until the application upgraded junit from 4.11 to 4.12. This error is shown now where ever I'm using powermock:
Field 'fTestClass' was not found in class org.junit.internal.runners.MethodValidator.
So I did some research and this problem was fixed in later releases of powermock and, in fact, it doesn't throw me that error when I went to 1.6.6 (nor 1.6.2+). But then something else is breaking:
java.lang.NoClassDefFoundError: org/mockito/internal/creation/util/MockitoMethodProxy
I already had this problem before, I tried with many versions to make it work until I came to the config I mention before ( Junit 4.11, Mockito 1.95, PowerMock 1.5.6). The online link I found where version compatibility is documented is here
https://github.com/powermock/powermock/wiki/MockitoUsage
But it only talks about mockito with powermock. I tried to combine versions (following the rules for mockito and powermock). I cannot change junit version, so I changed mokito to 2.0.0 and powermock 1.6.6 (as it the doc says it works), but the error persist. I tried 2.5.4 and 1.6.6, and with other versions of powermock. So far, I have not had any luck.
Does anyone know how to config this? Is there any doc about these compatibilities I'm missing?
Upvotes: 2
Views: 8102
Reputation: 666
I recommend use PowerMock with his Mockito and Junit4 version from the PowerMock repository to have the maximun compatibility from here:
Junit4: https://mvnrepository.com/artifact/org.powermock/powermock-module-junit4
Mockito: https://mvnrepository.com/artifact/org.powermock/powermock-api-mockito2
try to use the same version like this:
gradle example:
testCompile group: 'org.powermock', name: 'powermock-api-mockito2', version: '2.0.5'
testCompile group: 'org.powermock', name: 'powermock-module-junit4', version: '2.0.5'
that worked for me!
Upvotes: 1