如何使用Maven在特定程序包中运行所有测试? [英] How to run all tests in a particular package with Maven?

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

问题描述

我可以在 Maven文档它显示了如何运行:

I can find in the Maven docs where it shows how to run:

  1. 单项测试
  2. 所有测试都在一个测试类中
  3. 与特定模式匹配的类中的所有测试

但是如何在一个程序包中运行所有测试?这可能吗?

But how to run all the tests in a package? Is this possible?

我希望不需要修改pom.xml或代码的解决方案.

I would prefer solutions that don't require modifying the pom.xml or code.

推荐答案

例如,您也可以使用模式

You could use a pattern as well, for example

 mvn '-Dtest=de.mypackage.*Test' test

运行以>结尾的软件包 de.mypackage 中的类中的所有测试.

runs all tests in classes from package de.mypackage ending on *Test.

[更新2017/12/18]:
自从这成为公认的答案以来,这里有一些进一步的信息:

[update 2017/12/18]:
Since this became the accepted answer, here's some further information:

  • Maven使用 Maven Surefire插件来执行测试.
  • 上面使用的语法(合格的软件包名称)需要Surefire版本2.19.1或更高!早期版本要求使用路径表达式,例如

  • Maven uses the Maven Surefire plugin to execute tests.
  • The syntax used above (qualified package name) requires Surefire version 2.19.1 or higher! Earlier versions require the use of path expressions, for example

mvn -Dtest="de/mypackage/*Test" test

  • 我使用引号(`或)来防止外壳程序执行路径名扩展,Maven不需要任何引号.

  • I'm using quotes (` or ") to prevent the shell from performing pathname expansion, Maven doesn't require any quotes.

    可以使用以下语法提取单个测试方法

    A single test method can be exuted using the following syntax

    mvn -Dtest=MyUnitTest#testMethod test
    

  • 子包中的所有测试也可能包括在内,以便在包de.mypackage.sub中或以下执行所有测试:

  • All tests from subpackages may be includes as well, in order to execute all tests in or beneath package de.mypackage.sub execute:

    mvn -Dtest="de/mypackage/sub/**" test
    

    或Surefire 2.19.1或更高版本

    or with Surefire 2.19.1 or higher

    mvn -Dtest="de.mypackage.sub.**" test
    

  • 还有更多可能,例如使用正则表达式,请参见运行单个测试的官方文档.

    There are further possibilities like using regular expressions, see the official documentation of running a single test.

    这篇关于如何使用Maven在特定程序包中运行所有测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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