我知道您可以使用以下方法在某个类中运行所有测试:

mvn test -Dtest=classname

但我想运行一个单独的方法和-Dtest=classname。Methodname似乎不起作用。


当前回答

新版本的JUnit包含Categories运行器: http://kentbeck.github.com/junit/doc/ReleaseNotes4.8.html

但是JUnit的发布过程不是基于maven的,因此maven用户必须手动将其放入他们的存储库中。

其他回答

首先,你需要清理你的专业项目

mvn戒毒

然后您可以使用运行特定的文件和函数

mvn test -Dtest=testClassName#testCaseName

在单个测试类中运行一组方法 使用版本2.7.3,您只能在单个测试类中运行n个测试。

注意:junit 4支持。x和TestNG。

必须使用以下语法

mvn -Dtest=TestCircle#mytest test

你也可以使用模式

mvn -Dtest=TestCircle#test* test

从surefire 2.12.1开始,您可以选择多种方法(目前仅限JUnit4X,欢迎补丁)

mvn -Dtest=TestCircle#testOne+testTwo test

查看有关单个测试的链接

新版本的JUnit包含Categories运行器: http://kentbeck.github.com/junit/doc/ReleaseNotes4.8.html

但是JUnit的发布过程不是基于maven的,因此maven用户必须手动将其放入他们的存储库中。

您需要指定JUnit测试类及其要执行的方法。

mvn test -Dtest=com.mycompany.AppTest#testMethod

https://metamug.com/article/java/build-run-java-maven-project-command-line.html#running-unit-tests

这个命令有效!! 请注意,“-DTest”以大写字母“T”开头。