PowerMock + Mockito runtime error: ProxyFrameworkImpl could not be in the classpath

I'm trying to use PowerMock with Android InstrumentTestCase Since my test works on an Android device, libraries need to be added to apk.

I'm having big problems with powermock + mockito and Dex files. I have a runtime error with only powermock + mockito in my dependencies:

org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath. 

And a compilation error if I include cglib / cglib-nodep (suggested in the answers ):

 com.android.dex.DexException: Multiple dex files define Lnet/sf/cglib/beans/BeanCopier$BeanCopierKey 

Here is part of my gradle.build:

 androidTestCompile 'com.android.support.test:runner:0.3' androidTestCompile 'org.powermock:powermock-api-mockito:1.6.4' androidTestCompile 'org.powermock:powermock-module-junit4:1.6.4' androidTestCompile 'cglib:cglib-nodep:3.2.0' androidTestCompile 'cglib:cglib:3.2.0' 

What am I missing?

Thanks in advance!

+5
source share
1 answer

I also tried using PowerMock control tests for Android and was stuck in the same issue.

Here is what I found on PowerMock github

PowerMock will not work on Android if you run it on your device, as PowerMock uses JVM bytecode manipulation. It will work if you run it on the JVM.

So, I think PowerMock is only suitable for unit testing on Android.

+5
source

Source: https://habr.com/ru/post/1242385/


All Articles