Using PowerMock and Mockito in an Android Instrumentation test - Error - Duplicate files - org.mockito.plugins.MockMaker

后端 未结 3 2326
不知归路
不知归路 2021-02-20 11:29

I”m trying to use PowerMock to mock a class with a static method, but specifically I wish to do this within an Android Instrumentation test. To be clear I wish to run the test o

相关标签:
3条回答
  • 2021-02-20 11:46

    Do you have this into your project/module gradle?

    packagingOptions {
        exclude 'fileNameYouWantToExclude'
    }
    

    In this way Androd will put just one file if duplicates are found

    0 讨论(0)
  • 2021-02-20 12:03

    The only correct answer is PowerMockito does not support the Davik VM Android uses, it is meant for a standard JVM. So you can't use it with instrumented tests, only unit tests.

    0 讨论(0)
  • 2021-02-20 12:06

    I was able to workaround this issue with the following. If you see any error message that says Duplicate files copied in APK [filename], add that [filename] to be excluded in the packagingOptions.

    android {
        packagingOptions {
            exclude 'mockito-extensions/org.mockito.plugins.MockMaker'
        }
    }
    
    0 讨论(0)
提交回复
热议问题