Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Powermock complains about default.properties file found in 2 places

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.

like image 535
glisu Avatar asked Jun 20 '18 02:06

glisu


1 Answers

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 :-)

like image 73
forlayo Avatar answered Sep 20 '22 14:09

forlayo