java 如何使用 Maven 运行多个测试类或测试方法?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27653510/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to run multiple test classes or test methods using Maven?
提问by TDHM
In order to run all Maven tests, we can use:
为了运行所有 Maven 测试,我们可以使用:
mvn clean test
If we want to run specific test class, we can use:
如果我们想运行特定的测试类,我们可以使用:
mvn clean test -Dtest=className
If we want to run specific method from specific test class, we can use:
如果我们想从特定的测试类运行特定的方法,我们可以使用:
mvn clean test -Dtest=className#methodName
But I want to run:
但我想跑:
- multiple test classes(not all that belong to
src\test\java
) - multiple test methods from specific test class(not all test methods of specific test class that belong to
src\test\java
)
- 多个测试类(并非所有属于
src\test\java
) - 来自特定测试类的多个测试方法(并非属于特定测试类的所有测试方法
src\test\java
)
Are there Maven commands using which I can achieve above two?
是否有 Maven 命令使用我可以实现以上两个?
回答by Subir Kumar Sao
回答by jorrocks
You can use wildcards - note that you have to quote the test argument so the shell does not expand the wildcard.
您可以使用通配符 - 请注意,您必须引用 test 参数,以便 shell 不会扩展通配符。
mvn -Dtest="TestSquare,TestCi*le" test
(using maven-surefire-plugin:2.17)
(使用 maven-surefire-plugin:2.17)
回答by Krzysztof Walczewski
If You want to launch all test Clases from subdirectory, eg: /doc/ You can use command:
如果您想从子目录启动所有测试类,例如:/doc/ 您可以使用命令:
mvn -Dtest=*/doc/* test
回答by Sidharth Taneja
You can add multiple classes in TestNG with their groups, like
您可以在 TestNG 中添加多个类及其组,例如
<groups>
<run>
<include name = "checkintest" />
<include name = "videoSpider" />
<include name = "xmlTCUploader" />
<include name = "PALLogin" />
</run>
</groups>
<classes>
<class name="SeleniumUC"/>
<class name="PALTestCasesSuite"/>
</classes>
After this, you can use these group with Maven like -
在此之后,您可以将这些组与 Maven 一起使用,例如 -
mvn -Dgroups=PALLogin test