maven:如何通过命令行选项跳过某些项目中的测试?
在我的 Maven 项目中,我有许多模块。是否可以通过命令行选项关闭某些模块的运行单元测试?
我的项目大约需要 15 分钟才能完成所有单元测试。我想通过仅运行我正在处理的模块中的单元测试来加快整体构建速度。我不想进入并编辑每个单独的 pom.xml 来实现此目的。
我已经尝试了此处概述的解决方案: 我可以运行通过 Maven 进行特定的 testng 测试组? 然而,结果是我想跳过的模块中存在大量测试失败。我想“组”不是模块的同一概念吗?
In my maven project I have a number of modules. Is it possible to turn off running unit test for some modules via command line options?
My project takes about 15 mins to run through all unit tests. I would like to speed up the overall build by running just the unit tests in the module I am working on. I do not want to go in and edit each individual pom.xml to achieve this.
I have tried a solution outlined here: Can I run a specific testng test group via maven? However the result is a lot of test failures in modules that I want to skip. I suppose 'group' is not the same concept of module?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
要打开和关闭整个项目的单元测试,请使用 Maven Surefire Plugin 具有跳过测试的功能。从命令行使用skipTests 有一个缺点。在多模块构建场景中,这将禁用所有模块的所有测试。
如果您需要对运行模块的测试子集进行更精细的控制,请考虑使用 Maven Surefire 插件的测试包含和排除功能。
要允许命令行覆盖,请在配置 Surefire 插件时使用 POM 属性。以下面的 POM 段为例:
使用上面的 POM,您可以通过多种方式执行测试。
To toggle unit tests on and off for an entire project use Maven Surefire Plugin's capability of skipping tests. There is a drawback with using skipTests from the command line. In a multi-module build scenario, this would disable all tests across all modules.
If you need more fine grain control of running a subset of tests for a module, look into using the Maven Surefire Plugin's test inclusion and exclusion capabilities.
To allow for command-line overrides, make use of POM properties when configuring the Surefire Plugin. Take for example the following POM segment:
With a POM like the above you can execute tests in a variety of ways.
找到了一种在命令行上排除的方法:
这来自:使用 Maven 运行一项或排除一项测试
Found a way to exclude on command line:
This is from: Run one or Exclude one test with Maven
...如果你想将参数传递给 Hudson/Jenkins 中的 Maven 发布插件,你必须使用
-Darguments=-DskipTests
让它发挥作用。
…and if you like to pass the parameter to maven release plugin in Hudson/Jenkins you have to use
-Darguments=-DskipTests
to get it work.
如果您想使用 Maven 配置文件:
你可能想让它像这样工作:
不知道有没有支持的命令行选项具有相同的功能。
您也可以尝试直接使用环境属性,如本文档页面所示:
即类似:
然后使用
mvn -DmoduleA.skipTests=false test
测试该模块。If you want to use Maven profiles:
you might want to make it work doing something like this:
I don't know if there is a supported command line option that does the same.
You also might try using environment properties directly, something as per this doc page:
i.e. something like:
then using
mvn -DmoduleA.skipTests=false test
to test that one module.