[英]How to make integration tests and unit tests run separately through maven?
Refer following links - GitHub discussion on how to separate Integration Tests and Unit Tests 请参阅以下链接 - GitHub讨论如何分离集成测试和单元测试
As a result, I tried this -- 结果,我尝试了这个 -
<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>
This is working good to some extent. 这在某种程度上有效。 Meaning, surefire doesn't execute Integration tests and Failsafe doesn't execute unit tests. 意思是,surefire不执行集成测试,而Failsafe不执行单元测试。
But, when I run, mvn verify
or mvn integration-test
, the sure-fire plugin is also used. 但是,当我运行, mvn verify
或mvn integration-test
,也会使用sure-fire插件。
Required Outcome: When run mvn integration-test
, Unit test shouldn't be run. 必需结果:运行mvn integration-test
,不应运行单元测试。
The below three images are for mvn verify
以下三张图片用于mvn verify
Integration Test: 整合测试:
Unit Tests: 单元测试:
The below image is when I ran mvn test
下图是我运行mvn test
Maven has a build lifecycle made up out of several phases. Maven的构建生命周期由几个阶段组成。 When you call a particular one, all phases before that one will be executed first. 当您调用特定的某个阶段时,将首先执行该阶段之前的所有阶段。 See https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html 请参阅https://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html
There are two ways how you could solve what you want: 有两种方法可以解决你想要的问题:
-DskipTests
or -Dmaven.test.skip=true
( https://www.mkyong.com/maven/how-to-skip-maven-unit-test/ ) 使用-DskipTests
或-Dmaven.test.skip=true
( https://www.mkyong.com/maven/how-to-skip-maven-unit-test/ ) mvn clean test-compile failsafe:integration-test
直接调用插件目标mvn clean test-compile failsafe:integration-test
Both goals verify
and integration-test
defined in maven-failsafe-plugin
runs integration test cases with surefire. 在maven-failsafe-plugin
定义的目标verify
和integration-test
运行与surefire的集成测试用例。 Here things are working as expected and as per guideline provided. 这里的事情按预期工作,并按照指南提供。 pls refer this link for more details: 请参阅此链接以获取更多详细信息:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.