6

I am trying to use PowerMock with the Android InstrumentTestCase Since my test runs on an Android device the libraries needs to be added to the apk.

I encounter big issues 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 either cglib/cglib-nodep (has suggested in answers):

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

Here is a 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!

Community
  • 1
  • 1
nsvir
  • 8,781
  • 10
  • 32
  • 47
  • I'm having the same issue. Did you manage to find a solution? – Daniel Mar 09 '16 at 14:54
  • Not yet, I have postpone the issue. I tried to downloads the libraries and If you take a look at the content you can see that they have both the same jar. It should be removed from one library. – nsvir Mar 11 '16 at 15:33

1 Answers1

6

I also tried to use PowerMock for Android instrumentation tests and got stuck with the same issue.

Here is what I've found on PowerMock github

PowerMock won't work on Android if you run it on a device since PowerMock is using JVM byte code manipulation. It will work if you run it on a JVM though.

So, I guess PowerMock is only appropriate for unit testing on Android.

Andrew Panasiuk
  • 626
  • 1
  • 8
  • 17
  • Thanks for you answer! I have gave up because of a lack of information. – nsvir Apr 27 '16 at 14:30
  • Sure! Actually, there should be some different approaches to insert mock stuff into the instrumentation tests. For example, one can be redesigned to Robolectric unit test and then we can use either PowerMock or Mockito. As I remember I solved my problem this way. – Andrew Panasiuk Apr 27 '16 at 15:16