如何使用Maven运行多个测试类或测试方法? [英] How to run multiple test classes or test methods using Maven?

查看:333
本文介绍了如何使用Maven运行多个测试类或测试方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为了运行所有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

但我想跑:


  1. 多个测试类(并非所有属于 src\test\java

  2. 来自特定测试类的多个测试方法(不是特定测试类的所有测试方法属于 src\test\java

  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)

是否有Maven命令使用我可以达到的两个以上?

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

推荐答案

如果使用surefire插件,那么你可以使用以下选项。

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

参考 docs

这篇关于如何使用Maven运行多个测试类或测试方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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