I'm using Robolectric to test my app, I decided to use Powermock to mock static and final classes so I added the following dependencies to my build.gradle file:
testImplementation "org.powermock:powermock-module-junit4:1.7.0"
testImplementation "org.powermock:powermock-module-junit4-rule:1.7.0"
testImplementation 'org.powermock:powermock-api-mockito2:1.7.0'
testImplementation 'org.powermock:powermock-classloading-xstream:1.7.0'
Then I started to write tests and everything works fine except that every test that uses Powermock prints the following warning too:
Properties file org/powermock/default.properties is found in 2 places:
ConfigurationSource{location='file:/C:/Users/USUARIO/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-core/1.7.0/19f022747953e7eccc3e53253f709d726931f407/powermock-core-1.7.0.jar!/org/powermock/default.properties}
ConfigurationSource{location='file:/C:/Users/USUARIO/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-core/1.7.0/19f022747953e7eccc3e53253f709d726931f407/powermock-core-1.7.0.jar!/org/powermock/default.properties}
. Which one will be used is undefined. Please, remove duplicated configuration file (or second PowerMock jar file) from class path to have stable tests.Properties file org/powermock/default.properties is found in 2 places:
ConfigurationSource{location='file:/C:/Users/USUARIO/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-core/1.7.0/19f022747953e7eccc3e53253f709d726931f407/powermock-core-1.7.0.jar!/org/powermock/default.properties}
ConfigurationSource{location='file:/C:/Users/USUARIO/.gradle/caches/modules-2/files-2.1/org.powermock/powermock-core/1.7.0/19f022747953e7eccc3e53253f709d726931f407/powermock-core-1.7.0.jar!/org/powermock/default.properties}
. Which one will be used is undefined. Please, remove duplicated configuration file (or second PowerMock jar file) from class path to have stable tests.
Every test runs correctly however I want to get rid of that annoying warning message.
TL;DR;
To fix it add "org.powermock.*" to @PowerMockIgnore, like:
@PowerMockIgnore({ "org.powermock.*", "org.mockito.*", "org.robolectric.*", "android.*", "androidx.*" })
In my case I've been using Roboelectric + PowerMock + Mockito2 and I got same issue, as PowerMock is loading itself few times to set everything up as using another Runner than PowerMock one.
I hope this helps someone :-)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With