【问题标题】:Using Maven, how do I run specific tests?使用 Maven,我如何运行特定的测试?
【发布时间】:2011-11-25 23:40:31
【问题描述】:

我的项目中有数千个单元测试,我想选择其中的一个或几个从命令行运行。执行此操作的命令是什么?

【问题讨论】:

标签: unit-testing maven


【解决方案1】:

您可以通过将 -Dtest=<class> 标志传递给 Maven 来运行一个类中的所有测试:

mvn clean test -Dtest=xxxxTest

从 Surefire 2.8 开始,您还可以运行单个测试,例如在单元测试中使用方法 testA,使用相同的标志:

mvn clean test -Dtest=xxxxTest#testA

可以在Maven Surefire documentation > Running a Single Test 中找到更多按名称模式或名称列表运行多个测试的示例。

【讨论】:

  • maven.apache.org/surefire/maven-surefire-plugin/examples/… 出现,您也可以选择同时指定测试类方法名称,对吗?
  • 类列表怎么样? IE。 5 或 6 个测试课程?
  • 虽然 Maven Surefire 文档的标题是“运行单个测试”,但它也解释了如何运行多个测试。例如,mvn -Dtest=TestSquare,TestCi*le test
【解决方案2】:

请阅读这篇maven surefire plugin manual。基本上你可以做到以下几点:

mvn -Dtest=*PerformanceTest clean test 

仅运行以 PerformanceTest 结尾的所有测试类。

【讨论】:

    猜你喜欢
    • 2011-10-12
    • 2016-08-29
    • 2015-06-15
    • 2012-02-22
    • 2014-08-06
    • 1970-01-01
    • 2012-02-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多