在多模块Maven项目中构建所有模块后,如何运行集成测试? [英] How can I run integration tests after building all modules in a multi-module Maven project?

查看:220
本文介绍了在多模块Maven项目中构建所有模块后,如何运行集成测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个大型的多模块Maven项目.每个模块具有快速的单元测试(使用Surefire插件),许多模块具有缓慢的集成测试(使用Failsafe插件).

I am working on a large multi-module Maven project. Each module has fast unit tests (using the Surefire plugin), many modules have slow integration tests (using the Failsafe plugin).

我想通过在所有模块均已构建并进行单元测试之后从所有模块运行集成测试来加快对简单"构建失败(编译错误和单元测试失败)的反馈.

I would like to speed up the feedback for "simple" build failures (compilation errors and unit test failures) by running integration tests from all modules after all modules have been built and unit-tested.

您能建议实现此目标的好方法吗?

Can you suggest a good way of achieving this?

推荐答案

以下是完全符合我需要的解决方案:使用Failsafe插件仅运行集成测试,而无需将测试移出自然位置或在其中重新编译进行测试.

Here's a solution that does exactly what I want: using the Failsafe plugin to run just the integration tests without having to move tests out of their natural places or recompile in order to run the tests.

mvn install -DskipITs
mvn failsafe:integration-test

我们让Maven将项目的工件发布到本地目录中.然后,我们可以将其用作第二步的存储库.在第二步中,我们准确地调用了我们需要的目标,它从本地存储库中获取了工件.

We get Maven to publish the artifacts for the project into a local directory. We can then use that as a repository for the second step. In that second step we then invoke exactly the goal that we need and it grabs the artifacts from the local repository.

如果需要单独运行单元测试,则Surefire(mvn surefire:test)也可以使用同样的方法.

The same thing works for Surefire (mvn surefire:test) if you need to run unit tests separately.

我不得不承认我不完全了解Maven模型,因此为什么行得通.互联网似乎一致认为这种事情无法完成(请参见此处的其他答案),但这绝对对我有用.

I have to admit that I don't fully understand the Maven model and hence why this works. The internet seems unanimously of the view that this kind of thing can't be done (see other answers here), but it's definitely working for me.

这篇关于在多模块Maven项目中构建所有模块后,如何运行集成测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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