运行Maven测试命令时无测试运行 [英] No test run when running maven test command

查看:781
本文介绍了运行Maven测试命令时无测试运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个由其他人托管的Maven项目,该项目具有src/main目录和src/test目录. src/test目录包含一个以Test结尾的Java文件,我将其称为ATest.java,而类ATest仅包含一个静态void main 函数.就像

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

其中BTesterCTester都是目录下的文件 src/main/java/<package_path>/tester

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

当我键入mvn clean test时,它会显示

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

我尝试了以下方法:

  1. import org.junit.Test并在main函数之前添加@Test描述符,但是由于main是静态的并且接受参数,因此会出现错误.然后,我尝试将BTester.mainCTester.main移至另一个函数testmain,并在testmain之前添加@Test,但是在编译时会导致错误,说即使我添加了throws Exception,我也有未捕获的异常?

  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?

使用maven-surefire-plugin,这是我在pom.xml文件中执行的操作 <plugin> <artifactId>maven-surefire-plugin</artifactId> <version>2.20</version> <configuration> <includes> <include>ATest.java</include> </includes> </configuration> </plugin>

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>

但是它仍然不起作用.

我想念什么?我对Java不太熟悉,对maven也不很熟悉,所以我现在确实需要一些帮助.谢谢.

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

推荐答案

  1. 尝试将测试类放在/src/test/java下.
  2. 您需要测试方法.不要使用main作为使用JUNIT的测试方法 请参阅以下参考: http://www.vogella.com/tutorials/JUnit/article. html
  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

这篇关于运行Maven测试命令时无测试运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆