![](/img/trans.png)
[英]java.lang.Exception: No tests found matching Method using Intellij IDEA
[英]No tests found matching Method main in IntelliJ
我的课程是测试课程,它具有以下结构:
import org.junit.Test;
import org.junit.runner.RunWith;
import org.powermock.modules.junit4.PowerMockRunner;
@RunWith(PowerMockRunner.class)
public class MyClassTest {
public static void main(String[] args) {
System.out.println("in main");
}
@Test
public void maxTest() {
System.out.println("test");
}
}
如果我右键单击main
方法> Run'main',则会引发以下异常:
java.lang.Exception: No tests found matching Method main(MyClassTest) from org.junit.internal.requests.ClassRequest@26aa12dd
at org.junit.internal.requests.FilterRequest.getRunner(FilterRequest.java:35)
at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:41)
at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:212)
at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:68)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
如果我按右键单击类名> Run'MyClassTest.main()',则可以正常打印:
in main
如果我注释掉@RunWith(PowerMockRunner.class)
,则在两种情况下都可以正常工作。
如果我使用@RunWith(MockitoJUnitRunner.class)
而不是@RunWith(PowerMockRunner.class)
则会出现相同的问题。
为什么有区别呢?
细节:
抛出异常是因为main
方法上没有@Test
批注。
请检查您的类路径中是否有需要powermock的javassist库版本。
在这种情况下,Junit似乎无法报告正确的根故障原因。 有关详细信息,您可以看到此问题 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.