我有一个gradle文件
testCompile('junit:junit')
testCompile('org.powermock:powermock-core:1.6.5')
testCompile('org.powermock:powermock-api-mockito:1.6.5')
testCompile('org.powermock:powermock-module-junit4:1.6.5')
还有我的测试文件
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
@PrepareForTest(ExperimentService.class)
@RunWith似乎有错误,我似乎找不到问题,它只是说'@RunWith'不适用于方法。
我究竟做错了什么?
谢谢。
最佳答案
如果看到RunWith.class,则此注释的目标是ElementType.Type,这意味着它只能应用于Class,枚举或接口声明。
@Retention(RetentionPolicy.RUNTIME)
@Target({ElementType.TYPE})
@Inherited
public @interface RunWith {
Class<? extends Runner> value();
}
您不能在方法上应用此注释。
关于java - @RunWith(PowerMockRunner.class)说@RunWith不适用于方法,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/38301648/