在多模块 Maven 项目中构建阶段之前运行单元测试
我有一个多模块 Maven 项目。每个模块都有单元测试。当我在每个模块之前运行干净安装测试时,如果一个模块中的所有测试都成功,则它会成功构建。如果一项测试失败,该模块中的所有其他测试都会成功运行(或者某些测试成功,其他测试失败)。第一个失败单元测试所在的模块构建失败。其他模块将被跳过。 我想要这样的事情:首先在所有模块中运行所有单元测试,然后如果没有失败的测试,则构建所有模块,或者如果一个或模式模块中有一个或多个失败的测试,则跳过所有模块的构建。你能帮我吗?
I have a multi-module maven project. In every module there are unit tests. When I make clean install tests run before every module and if all tests in one module are success it build successfully. If one test failure all other tests in that module run successfully (or some run successfully, other failed). The build of module in what the first failure unit test is placed failed. Other modules are skipped.
I want such thing: first to run all unit tests in all modules, and after that if there is no failed tests build all modules, or if there is one or more failed tests in one or mode modules skip building of all modules. Can you help me with it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
运行:
请注意,如果您有模块间依赖关系(我假设您有),您可能无法真正执行此操作,因为您需要在运行测试之前构建依赖的 jar 文件在另一个模块中。
run:
note, if you have inter-module dependencies (which i assume you do), you probably can't really do this, as you will need to build the dependent jars before you can run the tests in the other module.
AFAIK 在 Maven 中这是不可能的。您正在尝试更改 Maven 构建生命周期,这在 Maven 中是不允许的。但是,您可以将一些配置参数传递给 Maven,这将影响测试。
这根本不会运行单元测试
这将导致 Maven 不会停止并继续模块构建过程,即使在测试阶段出现故障也是如此。
希望这有帮助
AFAIK its impossible in maven. You are trying to change a maven build lifecycle which is not allowed in maven. However there are a couple of configuration parameters you can pass to maven and this will affect the testing.
This won't run unit tests at all
This will cause maven to not stop and proceed the module building process even if there were failures during the test phase.
Hope, this helps
问题是:
模块可能相互依赖,为了解决这些依赖关系,您必须按顺序构建模块,否则它们将无法编译。所以你的问题没有明智的解决方案。
疯狂的解决方案会以某种方式聚合所有子项目的源代码(和外部依赖项),并在该集团上运行
compile
和test
,但这将是一个如此可怕的黑客行为,我'我很高兴他们没有这么做。The problem is:
the modules probably have dependencies upon each other, and to resolve those dependencies, you have to build the modules in order, or they won't compile. So there's no sane solution to your problem.
Insane solutions would somehow aggregate the sources (and external dependencies) from all child projects and run
compile
andtest
on that conglomerate, but it would be such a monstrous hack that I'm glad they didn't do it.