简体   繁体   English

找不到与IntelliJ中的Method main匹配的测试

[英]No tests found matching Method main in IntelliJ

My class is a test class and it has the following structure: 我的课程是测试课程,它具有以下结构:

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");
    }

}

If I press the right click on the main method > Run 'main', it throws the following exception: 如果我右键单击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)

If I press right click on the class name > Run 'MyClassTest.main()' it works fine printing: 如果我按右键单击类名> Run'MyClassTest.main()',则可以正常打印:

in main

If I comment out @RunWith(PowerMockRunner.class) , everything works fine in both cases. 如果我注释掉@RunWith(PowerMockRunner.class) ,则在两种情况下都可以正常工作。

The same problem appears if I use @RunWith(MockitoJUnitRunner.class) instead of @RunWith(PowerMockRunner.class) . 如果我使用@RunWith(MockitoJUnitRunner.class)而不是@RunWith(PowerMockRunner.class)则会出现相同的问题。

Why is that difference? 为什么有区别呢?

Details: 细节:

  • Windows 7 Windows 7的
  • JUnit 4.12 JUnit 4.12
  • PowerMock 1.6.2 PowerMock 1.6.2
  • Java 8 Java 8
  • Maven 3 Maven 3
  • IntelliJ IDEA 14.1.3 IntelliJ IDEA 14.1.3

抛出异常是因为main方法上没有@Test批注。

Please check that you have a powermock required version of javassist library in your classpath. 请检查您的类路径中是否有需要powermock的javassist库版本。

Junit seems not able to report the correct root failure reason in this case. 在这种情况下,Junit似乎无法报告正确的根故障原因。 For the details,you can see this issue . 有关详细信息,您可以看到此问题

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM