简体   繁体   中英

How to run multiple test classes or test methods using Maven?

In order to run all Maven tests, we can use:

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 )
  2. multiple test methods from specific test class(not all test methods of specific test class that belong to src\\test\\java )

Are there Maven commands using which I can achieve above two?

If using surefire plugin then you may use the below options.

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.

mvn -Dtest="TestSquare,TestCi*le" test

(using maven-surefire-plugin:2.17)

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

mvn -Dtest=*/doc/* test

You can add multiple classes in TestNG with their groups, like

<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 -

mvn -Dgroups=PALLogin test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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