【发布时间】:2017-09-14 03:51:32
【问题描述】:
参考以下链接 - GitHub discussion on how to separate Integration Tests and Unit Tests
结果,我尝试了这个--
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Tests.java</include>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/Abstract*.java</exclude>
<exclude>**/IT*.java</exclude>
<exclude>**/*IT.java</exclude>
<exclude>**/*ITCase.java</exclude>
<exclude>**/*IntegrationTest.java</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<includes>
<include>**/IT*.java</include>
<include>**/*IT.java</include>
<include>**/*ITCase.java</include>
<include>**/*IntegrationTest.java</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
这在某种程度上运作良好。这意味着,surefire 不执行集成测试,而 Failsafe 不执行单元测试。
但是,当我运行mvn verify 或mvn integration-test 时,也使用了sure-fire 插件。
要求的结果:运行 mvn integration-test 时,不应运行单元测试。
以下三张图片为mvn verify
集成测试:
单元测试:
下图是我跑mvn test时的样子
【问题讨论】:
-
遵循默认命名模式,不要添加多个包含/排除等。因为 maven-surefire-plugin 和 maven-failsafe-plugin 的默认值运行良好......配置上的约定是pardigm...所以只有在你真的需要时才配置一些东西。否则保持默认值。
-
FailSafe Naming convention。直到你提到我才知道这存在。
-
@khmarbaise 但是,sunfire 是否排除了故障安全插件的默认设置?
-
我建议您查看以下文档:maven.apache.org/surefire/maven-surefire-plugin/… 不需要排除...因为 maven-surefire 和 maven-failsafe 是通过包含工作的。见maven.apache.org/surefire/maven-failsafe-plugin/…
标签: java maven unit-testing testing integration-testing