gpt4 book ai didi

java - 如何通过maven让集成测试和单元测试分开运行?

转载 作者:塔克拉玛干 更新时间:2023-11-03 04:22:06 33 4
gpt4 key购买 nike

请引用以下链接 - 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 verifymvn integration-test 时,还使用了 sure-fire 插件。


要求的结果:当运行 mvn integration-test 时,不应运行单元测试。


下面三张图片用于mvn verify

集成测试:

Integration Test

Tests Run

单元测试:

Unit Test

下图是我运行mvn test

Unit Tests

最佳答案

Maven 的构建生命周期由多个阶段组成。当您调用一个特定的阶段时,该阶段之前的所有阶段都将首先执行。参见 https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html

有两种方法可以解决您想要的问题:

关于java - 如何通过maven让集成测试和单元测试分开运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469938/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com