我有一个 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,这意味着它只能应用于类、枚举或接口(interface)声明。
@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/