强制后集成阶段在集成阶段后始终完成 [英] Force post-integration phase to always complete after integration phase
问题描述
有没有办法强制 post-integration
阶段总是在 integration
阶段之后运行?集成
阶段的测试失败次数.
Is there a way to enforce the post-integration
phase to always run after the integration
phase? By always I mean in the advent of test failures during integration
phase.
我正在运行一个 Angular/Springboot 应用程序.我使用量角器来运行测试整个 Angular + Springboot 链的 e2e 测试.我设法将它集成到我的 Maven 构建中,以便我可以:
I am running an Angular / Springboot application. I use protractor to run e2e tests that test the whole Angular + Springboot chain. I managed to integrate this in my Maven build so that I can:
- 设置后端 Springboot 服务器
- 使用初始数据设置数据库
- 在
集成
阶段运行量角器
- setup the backend Springboot server
- setup a DB with initial data
- run protractor during the
integration
phase
带有以下插件:
spring-boot-maven-plugin
启动和停止测试服务器以进行集成测试:
spring-boot-maven-plugin
which starts and stops a test server for integration testing:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
...
</configuration>
<executions>
<execution>
<id>pre-integration-test</id>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>post-integration-test</id>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
和 frontend-maven-plugin
在 integration
阶段运行我的量角器测试:
and frontend-maven-plugin
which runs my protractor tests during the integration
phase:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<configuration>
...
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<phase>generate-resources</phase>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>npm run integration tests</id>
<goals>
<goal>npm</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<arguments>run e2e</arguments>
<testFailureIgnore>true</testFailureIgnore> // this should probably be deleted
</configuration>
</execution>
</executions>
</plugin>
我将 testFailureIgnore = true
添加到 frontend-maven-plugin
因为如果任何量角器测试失败,它会在执行 后集成
阶段.这会导致测试服务器继续使用该端口运行.任何后续运行都将失败,因为该端口已经在使用中,直到该服务器被终止(手动).testFailureIgnore
属性允许构建忽略失败的测试,有效地让我继续post-integration
阶段.
I added testFailureIgnore = true
to the frontend-maven-plugin
because if any protractor test fails, it will stop my maven build before it gets to execute the post-integration
phase. This causes the test server to keep running with that port. Any subsequent runs will fail since the port is already in use until that server is killed (manually). The testFailureIgnore
property allows failed tests to be ignored by the build, effectively letting me continue with the post-integration
phase.
明显的缺点是即使测试失败,我的构建也会打印SUCCESS.我正在寻找类似于 failsafe
插件的行为,其中失败的测试将使我的构建失败,但仍会首先执行 post-integration
阶段以正确清理.
The obvious downside is that my build will print SUCCESS even when tests have failed. I am looking for behavior similar to the failsafe
plugin where failed tests will fail my build, but will still execute the post-integration
phase first to cleanup properly.
我似乎无法为此找到合适的解决方案,但我肯定不会是第一个遇到此问题的人.对此有哪些解决方案/替代方案?我想使用 exec-maven-plugin
而不是 frontend-maven-plugin
会导致同样的问题.
I can't seem to find a proper solution for this but surely I can't be the first to encounter this problem. What solutions/alternatives are available for this? I imagine using the exec-maven-plugin
instead of the frontend-maven-plugin
will cause the same issue.
推荐答案
我没有在任何地方找到合适的解决方案,所以我决定尝试创建自己的解决方案.我使用一个参数扩展了 frontend-maven-plugin
,该参数在 integration-test
阶段记录了集成测试失败,但仅在 verify
阶段失败了构建代码>阶段.这允许 post-integration-test
阶段完成.
I didn't manage to find a decent solution to this anywhere so I decided to try and create my own. I extended the frontend-maven-plugin
with a parameter that logs integration test failures during the integration-test
phase, but only fails the build during the verify
phase. This allows the post-integration-test
phase to finish.
我的解决方案可从 我的存储库获得(版本 1.9.1-failsafe
).此实现需要添加配置参数 integrationTestFailureAfterPostIntegration.不幸的是,我没有弄清楚如何在没有用户干预的情况下让 Mojo 执行在稍后阶段触发另一个 Mojo 执行.因此,用户需要在 verify
阶段触发执行,即使它在功能上没有做任何有用的事情(即 npm -version
).
My solution is available from my repository (version 1.9.1-failsafe
). This implementation requires a configuration parameter integrationTestFailureAfterPostIntegration to be added. Unfortunately I did not figure out how to make a Mojo execution trigger another Mojo execution at a later phase without user intervention. Because of this the user needs to have an execution that trigger during the verify
phase, even if it doesn't do anything useful functionally (ie. npm -version
).
我的工作示例:
<execution>
<id>npm run integration tests</id>
<goals>
<goal>npm</goal>
</goals>
<phase>integration-test</phase>
<configuration>
<arguments>run e2e</arguments>
<integrationTestFailureAfterPostIntegration>true</integrationTestFailureAfterPostIntegration>
</configuration>
</execution>
<execution>
<id>fail any integration tests</id>
<goals>
<goal>npm</goal>
</goals>
<phase>verify</phase>
<configuration>
<arguments>-version</arguments>
</configuration>
</execution>
如果任何 IT 测试失败,它们将在 integration-test
阶段被记录下来,并在 verify
中失败.如果所有 IT 测试均通过,则构建将成功.
If any IT tests fail, they will be logged during integration-test
phase and fail the build at verify
. If all IT tests pass, the build will be successful.
我在 有一个 开放拉取请求frontend-maven-plugin
可能会添加到 1.9.2 版本中.我仍然会尝试通过消除手动添加 verify
执行阶段的需要来改进更改.欢迎对拉取请求提出建议或改进!
I have an open pull request at the frontend-maven-plugin
which might get added to the 1.9.2 version. I will still attempt to improve upon the change by removing the need for the verify
execution phase to be added manually. Suggestions or improvements on the pull request are welcome!
更新:我已经继续发布了我自己的版本,以防拉取请求没有通过:
UPDATE: I already went ahead and released my own version in case the pull request doesn't come through:
<dependency>
<groupId>io.github.alexandertang</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.9.1-failsafe</version>
</dependency>
在这个版本中,我添加了一个 verify
mojo,它简化了第二次执行:
In this version I added a verify
mojo which simplifies the second execution to:
<execution>
<id>fail any integration tests</id>
<goals>
<goal>verify</goal>
</goals>
<phase>verify</phase> <!--default phase is verify, so this is optional-->
</execution>
这篇关于强制后集成阶段在集成阶段后始终完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!