【问题标题】:How to make integration tests and unit tests run separately through maven?如何通过maven让集成测试和单元测试分开运行?
【发布时间】: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 verifymvn integration-test 时,也使用了sure-fire 插件。


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


以下三张图片为mvn verify

集成测试:

单元测试:

下图是我跑mvn test时的样子

【问题讨论】:

标签: java maven unit-testing testing integration-testing


【解决方案1】:

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

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

【讨论】:

    【解决方案2】:

    maven-failsafe-plugin 中定义的两个目标 verifyintegration-test 都可以运行集成测试用例。这里的事情按预期工作,并按照提供的指导方针。请参考这个link 更多详情:

    【讨论】:

    • 这是真的。谢谢。但是,它实际上并没有解决我的核心问题。
    猜你喜欢
    • 2012-05-05
    • 1970-01-01
    • 2012-01-01
    • 2016-01-23
    • 2015-07-19
    • 1970-01-01
    • 1970-01-01
    • 2010-10-23
    • 2013-03-18
    相关资源
    最近更新 更多