Deployment 部署到集成服务器并使用Maven运行冒烟测试

Deployment 部署到集成服务器并使用Maven运行冒烟测试,deployment,maven,continuous-integration,Deployment,Maven,Continuous Integration,我们正在使用Maven构建一个web应用程序 现在,我们希望我们的CI(持续集成)服务器能够自动将WAR部署到远程Tomcat实例,该实例充当alpha测试服务器 我们使用cargo maven插件来实现这一点,它运行良好 但是,现在我们还希望在部署后在远程Tomcat上运行冒烟测试,以确保(重新)部署顺利进行 我们有测试来做这件事(使用HtmlUnit),但是我们在将它们集成到Maven中时遇到了困难。到目前为止,我们直接启动了cargo(使用mvn cargo:redeploy)。这是有效的

我们正在使用Maven构建一个web应用程序

现在,我们希望我们的CI(持续集成)服务器能够自动将WAR部署到远程Tomcat实例,该实例充当alpha测试服务器

我们使用cargo maven插件来实现这一点,它运行良好

但是,现在我们还希望在部署后在远程Tomcat上运行冒烟测试,以确保(重新)部署顺利进行

我们有测试来做这件事(使用HtmlUnit),但是我们在将它们集成到Maven中时遇到了困难。到目前为止,我们直接启动了cargo(使用
mvn cargo:redeploy
)。这是有效的-但是,我们找不到一种方法来运行烟雾测试之后

那么我们怎样才能让maven

  • 首先使用货物进行部署
  • 然后运行烟雾测试
在maven构建生命周期中似乎没有这样的位置。
我们是否需要定义自定义构建生命周期?我们能否以某种方式绑定到默认的生命周期阶段?哪一个?

您必须做的最重要的事情是将您的集成放在一个单独的maven模块中,不管它叫什么(用于集成测试)。将cargo插件放入集成阶段:

<plugin>
    <groupId>org.codehaus.cargo</groupId>
    <artifactId>cargo-maven2-plugin</artifactId>
    <configuration>
      <wait>false</wait>
      <container>
        <containerId>tomcat${tomcat.major}x</containerId>
        <zipUrlInstaller>
          <url>http://archive.apache.org/dist/tomcat/tomcat-${tomcat.major}/v${tomcat.version}/bin/apache-tomcat-${tomcat.version}.tar.gz</url>
          <downloadDir>${project.build.directory}/cargo/download/</downloadDir>
          <extractDir>${installDir}</extractDir>
        </zipUrlInstaller>
        <output>${project.build.directory}/tomcat${tomcat.major}x.log</output>
        <log>${project.build.directory}/cargo.log</log>
      </container>
      <configuration>
        <home>${project.build.directory}/tomcat-${tomcat.version}/container</home>
        <properties>
          <cargo.logging>high</cargo.logging>
          <cargo.servlet.port>9080</cargo.servlet.port>
        </properties>
      </configuration>
    </configuration>

org.codehaus.cargo
. 最后,您必须将集成测试放在集成测试模块的src/test/java文件夹中,不要忘记配置maven surefire插件,如下所示:

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
      <execution>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <printSummary>true</printSummary>
      <testFailureIgnore>true</testFailureIgnore>
    </configuration>
  </plugin>

org.apache.maven.plugins

. 对此进行了描述。

使用集成测试阶段进行部署并在其上运行测试如何?你可以简单地运行mvn验证…@khmarbaise:Hm,我仍在试图理解构建生命周期,以及扩展它的最“像maven”的方式,但这是有意义的。我会试试…@khmarbaise:顺便说一句,为什么不把它变成一个答案呢?谢谢你提供的信息。这或多或少就是我们最终要做的(主要区别在于我们使用的远程Tomcat已经在运行,所以不需要启动/停止)。
      <execution>
        <id>stop-container</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <executions>
      <execution>
        <phase>integration-test</phase>
        <goals>
          <goal>test</goal>
        </goals>
      </execution>
    </executions>
    <configuration>
      <printSummary>true</printSummary>
      <testFailureIgnore>true</testFailureIgnore>
    </configuration>
  </plugin>