如何使集成测试和单元测试通过Maven分开运行? [英] How to make integration tests and unit tests run separately through maven?

查看:141
本文介绍了如何使集成测试和单元测试通过Maven分开运行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请参考以下链接- 关于如何分离集成测试和单元测试的GitHub讨论

结果,我尝试了--

     <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不会执行单元测试.


This is working good to some extent. Meaning, surefire doesn't execute Integration tests and Failsafe doesn't execute unit tests.

但是,当我运行mvn verifymvn integration-test时,也会使用sure-fire插件.

But, when I run, mvn verify or mvn integration-test, the sure-fire plugin is also used.

所需结果:运行mvn integration-test时,不应运行单元测试.

Required Outcome: When run mvn integration-test, Unit test shouldn't be run.

下面的三个图像是mvn verify

集成测试:

单元测试:

下图是我运行mvn test

推荐答案

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

Maven has a build lifecycle made up out of several phases. 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

有两种方法可以解决所需的问题:

There are two ways how you could solve what you want:

  • use -DskipTests or -Dmaven.test.skip=true (https://www.mkyong.com/maven/how-to-skip-maven-unit-test/)
  • call the plugin goal directly mvn clean test-compile failsafe:integration-test

这篇关于如何使集成测试和单元测试通过Maven分开运行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆