在一个阶段多次运行 exec-maven-plugin
我正在尝试测试客户端/服务器应用程序,并使用 Maven 来处理构建/测试/部署。要测试应用程序,我需要:
- 运行安装程序脚本(以安装服务器),
- 启动启动命令(以启动服务),
- 运行测试(maven-surefire-plugin),
- 停止服务,然后
- 卸载服务。
步骤 1、2、4 和 5 将使用 maven-exec-plugin。第 3 步将使用 maven-surefire-plugin。
问题是所有这 5 个步骤都将发生在“测试”阶段。 Maven 允许插件按特定顺序执行。 exec-plugin 可以通过使用多个条目多次运行。问题是我需要在 4 个 exec-plugin 执行中间使用 Surefire-plugin。
有没有人曾经遇到过这个问题,或者知道如何构建插件和执行?
I'm trying to test a client/server application, and using Maven to handle the build/test/deploy. To test the application, I need to:
- run an installer script (to install the server),
- kick off a startup command (to start the service),
- run the test (maven-surefire-plugin),
- stop the service, and
- uninstall the service.
Steps 1,2,4 and 5 will use the maven-exec-plugin. Step 3 will use the maven-surefire-plugin.
The problem is that all 5 of these steps will occur in the 'test' phase. Maven allows plugins in to be executed in a specific order. the exec-plugin can be run multiple times by using multiple entries. The problem is that I need to use the surefire-plugin in the middle of the 4 exec-plugin executions.
Has anyone ever run into this before, or know how to structure the plugin's and execution's?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这就是我配置执行和故障安全插件的方式。我正在使用故障保护,而不是重新配置 Surefire,因为 Surefire 仍在测试阶段运行其他测试。这将在预集成测试阶段运行步骤 1 和 2(同一阶段列出的多个执行将按照给定的顺序执行),在集成测试阶段运行测试,然后使用步骤 3 和 4 进行清理。集成后测试阶段。
(注意:我用 echo 命令代替了真正的安装和清理命令)
This is how I configured the exec and failsafe plugins. I'm using failsafe, rather than reconfiguring surefire, since surefire is still running other tests to be in the test phase. This will run steps 1 and 2 in the pre-integrationtest phase (multiple executions listed for the same phase will execute in the order given), run the test in the integration-test phase, and then clean up with steps 3 and 4 in the post-integrationtest phase.
(Note: I have echo commands in place of the real installation and cleanup commands)
您尝试做的事情听起来更像是集成测试而不是单元测试。对于此用例,默认 Maven 生命周期与集成测试相关的三个阶段:
pre-integration-test
:在执行集成测试之前执行所需的操作。这可能涉及诸如设置所需环境之类的事情。integration-test
:如有必要,处理包并将其部署到可以运行集成测试的环境中。post-integration-test
:执行集成测试后执行所需的操作。这可能包括清理环境。Surefire 插件通常在
test
阶段执行,但可以重新配置为在另一个阶段执行。然后,您可以将步骤 1 + 2 配置为在pre-integration-test
中执行,而步骤 4 + 5 必须在post-integration-test
中执行。What you are trying to do sounds more like an integration test than a unit test. For this use case the default maven lifecycle has three phases related to integration testing:
pre-integration-test
: perform actions required before integration tests are executed. This may involve things such as setting up the required environment.integration-test
: process and deploy the package if necessary into an environment where integration tests can be run.post-integration-test
: perform actions required after integration tests have been executed. This may including cleaning up the environment.The surefire plugin usually executes in the
test
phase, but can be reconfigured to execute in another phase. Your steps 1 + 2 can then be configured to execute inpre-integration-test
, while steps 4 + 5 have to execute inpost-integration-test
.