【发布时间】:2020-03-30 16:53:36
【问题描述】:
有没有办法强制post-integration 阶段始终在integration 阶段之后运行?我的意思是在integration 阶段出现测试失败时。
我正在运行一个 Angular / Springboot 应用程序。我使用量角器来运行测试整个 Angular + Springboot 链的 e2e 测试。我设法将它集成到我的 Maven 构建中,以便我可以:
- 设置后端 Springboot 服务器
- 使用初始数据设置数据库
- 在
integration阶段运行量角器
使用以下插件:
spring-boot-maven-plugin 启动和停止测试服务器以进行集成测试:
<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 阶段运行我的量角器测试:
<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 中,因为如果任何量角器测试失败,它将在执行post-integration 阶段之前停止我的maven 构建。这会导致测试服务器继续使用该端口运行。任何后续运行都将失败,因为该端口已在使用中,直到该服务器被杀死(手动)。 testFailureIgnore 属性允许构建忽略失败的测试,有效地让我继续 post-integration 阶段。
明显的缺点是即使测试失败,我的构建也会打印 SUCCESS。我正在寻找类似于failsafe 插件的行为,其中失败的测试将使我的构建失败,但仍会首先执行post-integration 阶段以正确清理。
我似乎找不到合适的解决方案,但我肯定不会是第一个遇到这个问题的人。有哪些解决方案/替代方案可用于此?我想使用exec-maven-plugin 而不是frontend-maven-plugin 会导致同样的问题。
【问题讨论】:
标签: spring-boot maven