I'm trying to use Powermock for the first time
I use build.gradle and added:
dependencies { ... testCompile 'org.mockito:mockito-all:1.9.5' testCompile 'org.powermock:powermock-api-mockito:1.5.5' }
now I look at my test class which has:
import org.junit.Before; import org.junit.runner.RunWith; import org.mockito.Matchers; import org.powermock.core.classloader.annotations.PrepareForTest; @RunWith(PowerMockRunner.class) @PrepareForTest(GeoUtils.class)
and get this error:
@RunWith(PowerMockRunner.class) ^ cannot resolve symbol PowerMockRunner
how come it resolves PrepareForTest
and not PowerMockRunner
?
Power mock is not compatible with JUnit5 So we will discuss it will JUnit4.
Annotation Type PowerMockIgnoreThis annotation tells PowerMock to defer the loading of classes with the names supplied to value() to the system classloader. For example suppose you'd like to defer the loading of all classes in the org.
Annotation Type PrepareForTestThis annotation tells PowerMock to prepare certain classes for testing. Classes needed to be defined using this annotation are typically those that needs to be byte-code manipulated.
PowerMockRunner is part of powermock-module-junit4.jar
. You need to explicity import this jar
You could specify the dependency for this jar as per your requirement. Refer to this link.
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