java - 如何防止 Maven Surefire 自动运行 Spring 集成测试
问题描述
我的集成测试需要很长时间才能运行,我不希望我的开发人员每次需要编译时都浪费时间。我只希望我的集成测试运行:
- 在我的 CI/CD 服务器中。
- 当我告诉我的 IDE (NetBeans) 专门运行一个测试文件时。
这可能吗?我怎样才能实现它?
解决方案
在您的 POM 中添加一个配置,在您的正常构建期间排除集成测试(假设您的集成测试被命名为UserService_IT.java
.
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skipTests>${skip.surefire.tests}</skipTests>
<excludes>
<exclude>**/*_IT*.java</exclude>
</excludes>
</configuration>
要运行集成测试,比如说在您的 CI 构建中,添加一个配置文件并在您的管道中激活它,例如mvn verify -Pintegration-tests
.
<profile>
<id>integration-tests</id>
<activation>
<activeByDefault>false</activeByDefault>
<property>
<name>integration-tests</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<configuration>
<includes>
<include>**/*_IT.java</include>
</includes>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
推荐阅读
- solidity - 我需要帮助来理解以下代码
- listview - Xamarin Forms更改ListView中每个ViewCell的背景颜色
- json - 显示 json 对象属性 | 离子项目和 Laravel Restful Api
- excel - 计算具有相似数据的唯一单元格在 Excel 中的列之间计数
- selenium - 如何处理应用程序中的动态错误消息
- python - 我在使用这个 pygame 代码时遇到了一些问题
- c - 使用 realloc() 初始化内存
- java - 同一实体上的多对多
- python - 如何支持 Flask-SSE 访问控制
- kepler.gl - 如何从 Kepler 中的 url 加载数据?