1

I am using Mockito framework for mocking objects for writing instrumentation tests. But I am not able to mock static methods using Mockito. I know this is not possible using Mockito alone and the recommended solution is to use PowerMock on top of Mockito. But when I use PowerMock, it throws the following exception.

java.lang.IllegalStateException: Extension API internal error: org.powermock.api.extension.proxyframework.ProxyFrameworkImpl could not be located in classpath.

Searching for this exception shows that it is because PowerMock produces .class files but for running instrumentation tests we need to have .dex file. Therefore the solution was to add dexmaker library. Therefore I added the dexmaker library.

androidTestCompile 'com.google.dexmaker:dexmaker:1.2'
androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.2'

But after adding that library, I am getting the below exception at compile time.

    Error:Execution failed for task ':app:transformResourcesWithMergeJavaResForDebugAndroidTest'.
> com.android.build.api.transform.TransformException: com.android.builder.packaging.DuplicateFileException: Duplicate files copied in APK mockito-extensions/org.mockito.plugins.MockMaker
    File1: C:\Users\anshul.jain\.gradle\caches\modules-2\files-2.1\org.powermock\powermock-api-mockito\1.6.4\fe12509b7e9e49d25131f4155145748a31e42e40\powermock-api-mockito-1.6.4.jar
    File2: C:\Users\anshul.jain\.gradle\caches\modules-2\files-2.1\com.google.dexmaker\dexmaker-mockito\1.2\b99884a4c6ef6335ba376f79aa79632b2421c17c\dexmaker-mockito-1.2.jar

I am not able to mock static methods using Mockito. Any solution for this?

thedarkpassenger
  • 7,158
  • 3
  • 37
  • 61

0 Answers0