绑定到maven中的生命周期不适用于故障安全和集成测试

时间:2014-05-21 13:59:28

标签: java maven maven-failsafe-plugin

当尝试将failafe绑定到生命周期时,根本不会执行任何操作。我已阅读this guidethis related question,根据此信息,当我指定时,应该可以让maven在integration-test执行故障安全目标integration-test它位于pom.xml中的build/pluginManagement/plugins - 部分,如下所示:

              <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <configuration>
                    <includes>
                        <include>**/*IT</include>
                    </includes>
                </configuration>
                <executions>
                    <execution>
                        <id>failsafe-integration-tests</id>
                        <phase>integration-test</phase>
                        <goals>
                            <goal>integration-test</goal>
                        </goals>
                    </execution>
                    <execution>
                        <id>failsafe-verify</id>
                        <phase>verify</phase>
                        <goals>
                            <goal>verify</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

不幸的是,这并没有强迫maven运行failafe:完全集成测试(mvn integration-test和mvn verify都没有)

但是,如果我尝试使用带有这样的插件规范的failsafe(来自here并添加了配置):

             <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-failsafe-plugin</artifactId>
                <version>2.17</version>
                <executions>
                    <execution>
                        <id>integration-test</id>
                        <goals>
                            <goal>integration-test</goal>
                            <goal>verify</goal>
                        </goals>
                        <phase>integration-test</phase>
                        <configuration>
                            <includes>
                                <include>**/*IT</include>
                            </includes>
                        </configuration>
                    </execution>
                </executions>
            </plugin>

至少maven编译failafe:集成测试运行。但不幸的是,这并没有称之为集成前和集成后测试。我现在已经捣乱了一段时间,并且毫无头绪 - 它应该受到限制。

有人知道为什么会这样,或者我如何解决它?

1 个答案:

答案 0 :(得分:1)

你所做的就是只在pluginManagement 中定义它,但你必须像这样运行它。 pluginManagement中的定义是固定插件版本的好习惯。

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>
        <executions>
          <execution>
            <goals>
              <goal>integration-test</goal>
              <goal>verify</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

除此之外,没有必要为maven-failsafe-plugin cause it has already defaults defined提供包含规则,因此不需要。