简体   繁体   English

如何使用 Maven 运行多个测试类或测试方法?

[英]How to run multiple test classes or test methods using Maven?

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:但我想跑:

  1. multiple test classes(not all that belong to src\\test\\java )多个测试类(并非所有属于src\\test\\java
  2. multiple test methods from specific test class(not all test methods of specific test class that belong to src\\test\\java )来自特定测试类的多个测试方法(并非属于src\\test\\java的特定测试类的所有测试方法)

Are there Maven commands using which I can achieve above two?是否有 Maven 命令使用我可以实现以上两个?

If using surefire plugin then you may use the below options.如果使用surefire插件,那么您可以使用以下选项。

For multiple classes you can use,对于您可以使用的多个类,

mvn -Dtest=TestSquare,TestCi*le test

For multiple methods in same class you can use,对于您可以使用的同一类中的多个方法,

mvn -Dtest=TestCircle#testOne+testTwo test

Refer docs参考文档

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)

如果您想从子目录启动所有测试类,例如:/doc/ 您可以使用命令:

mvn -Dtest=*/doc/* test

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

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

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