No test run when running maven test command

青春壹個敷衍的年華 提交于 2020-01-03 01:12:28

问题


There is a maven project hosted by someone else, which has src/main directory and src/test directory. The src/test dir contains a java file ending with Test, I'll just call it ATest.java, and the class ATest only contains a static void main function. It is like

//omitted

public class ATest {
    public static void main(String[] args) throws Exception {
        BTester.main(null);
        CTester.main(null);
    }
}

where BTester and CTester are both files under directory src/main/java/<package_path>/tester

When I type mvn clean test, it shows

[INFO] -------------------------------------------------------
[INFO]  T E S T S
[INFO] -------------------------------------------------------
[INFO] 
[INFO] Results:
[INFO] 
[INFO] Tests run: 0, Failures: 0, Errors: 0, Skipped: 0

I tried the following methods:

  1. import org.junit.Test and add @Test descriptor ahead of the main function, but it gives error because main is static and it accepts parameters. Then I tried to move BTester.main and CTester.main to another function testmain and add @Test before testmain, but it causes errors when compiling, saying that I have uncaught exception, even if I add throws Exception?

  2. use the maven-surefire-plugin, here is how I did it in the pom.xml file <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <includes> <include>ATest.java</include> </includes> </configuration> </plugin>

But it still doesn't work.

What did I miss? I'm not very familiar with Java, not with maven, so I really need some help now. Thanks.


回答1:


  1. Try to place your test class under /src/test/java.
  2. You need your test method. Do not using main for test method using JUNIT See this reference: http://www.vogella.com/tutorials/JUnit/article.html


来源:https://stackoverflow.com/questions/43833127/no-test-run-when-running-maven-test-command

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!