Maven - 运行集成和单元测试

时间:2016-08-16 23:43:40

标签: java maven unit-testing

我在Maven中定义了两组测试 - 集成测试和测试。

如果我运行maven test - 我的测试运行

如果我运行maven integration-test - 都运行

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.4.3</version>
    <executions>
      <execution>
        <id>default-test</id>
        <configuration>
          <forkMode>always</forkMode>
          <excludes>
            <exclude>**/TC_Integration*</exclude>
          </excludes>
          <includes>
            <include>**/TC_*</include>
          </includes>
        </configuration>
      </execution>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
        <configuration>
          <excludes>
            <exclude>**/TC_Unit*</exclude>
          </excludes>
          <includes>
            <include>**/TC_*</include>
          </includes>
        </configuration>
      </execution>
    </executions>
  </plugin>
  <plugin>

让两者同时运行的最佳方法是什么?我主要希望maven install同时运行,但事实并非如此。

1 个答案:

答案 0 :(得分:2)

不要试图配置surefire以运行单元测试和集成测试,而是配置surefire以仅运行单元测试并使用failsafe插件来运行集成测试。

https://maven.apache.org/surefire/maven-failsafe-plugin/