Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot resolve symbol PowerMockRunner

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 ?

like image 722
Elad Benda2 Avatar asked Jul 31 '14 14:07

Elad Benda2


People also ask

Does junit 5 support PowerMock?

Power mock is not compatible with JUnit5 So we will discuss it will JUnit4.

What is PowerMockIgnore?

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.

What is @PrepareForTest?

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.


1 Answers

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.

like image 54
Balaji Katika Avatar answered Sep 24 '22 08:09

Balaji Katika