cannot resolve symbol PowerMockRunner
Solution 1
You need to import PowerMockRunner
as follows:
import org.powermock.modules.junit4.PowerMockRunner;
Solution 2
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.
Solution 3
You just need to add the gradle dependency
testCompile "org.powermock:powermock-module-junit4:1.6.4"
or if you're use Android Studio version 3+
testImplementation "org.powermock:powermock-module-junit4:1.6.4"
Solution 4
I faced this error because I had only the first of the following dependencies added in my pom.xml. Please ensure you add both the following maven dependencies for PowerMock to your pom.xml.
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-api-mockito</artifactId>
<version>1.6.3</version>
</dependency>
<dependency>
<groupId>org.powermock</groupId>
<artifactId>powermock-module-junit4</artifactId>
<version>1.6.3</version>
</dependency>
Solution 5
I also faced with a similar error. Although the jars are already in the classpath, eclipse didn't suggest to import PowerMockRunner class. It was giving error "Class cannot be resolved to a type". I had to manually add the import "org.powermock.modules.junit4.PowerMockRunner
".
Related videos on Youtube
Elad Benda2
Updated on July 09, 2022Comments
-
Elad Benda2 almost 2 years
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 notPowerMockRunner
?-
David Conrad almost 10 yearsBecause you imported PrepareForTest, but you forgot to import PowerMockRunner?
-
Elad Benda2 over 9 yearsit doesn't give me any suggestion to
PowerMockRunner
import as it did withPrepareForTest
. So I guess it cannot resolve its import anyhow. no?what is it? -
David Conrad over 9 yearsI believe it should be
org.powermock.modules.junit4.PowerMockRunner
. If it doesn't accept the import, the dependency must not have been resolved for some reason. -
Elad Benda2 over 9 yearsthanks. please write an answer and I'll vote you
-
-
Muthaiah PL about 6 yearsI already have this import. But still i didn't work. I have the jar as well.
-
Muthaiah PL about 6 yearsI already have the import and the jar. But still i didn't work.