【问题标题】:Deploy to integration server and run smoke test with Maven部署到集成服务器并使用 Maven 运行冒烟测试
【发布时间】:2011-08-03 10:56:17
【问题描述】:

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

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

我们使用 cargo-maven-plugin 来执行此操作,它运行良好。

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

我们有测试可以做到这一点(使用 HtmlUnit),但我们无法将它们集成到 Maven 中。到目前为止,我们直接启动了货物(使用mvn cargo:redeploy)。这行得通 - 但是,我们找不到之后运行冒烟测试的方法。

那么我们如何设置maven到

  • 首先使用 cargo 部署
  • 然后运行冒烟测试

在 Maven 构建生命周期中似乎没有这个位置。 我们是否需要定义自定义构建生命周期?我们可以以某种方式绑定到默认的生命周期阶段吗?哪一个?

【问题讨论】:

  • 如何使用集成测试阶段进行部署并在其上运行测试?比你 CI 可以简单地运行 mvn verify ...
  • @khmarbaise:嗯,我仍在尝试了解构建生命周期以及扩展它的最“类似 maven”的方式,但这是有道理的。我试试看……
  • @khmarbaise:顺便说一句,为什么不把它变成一个答案呢?

标签: deployment maven continuous-integration


【解决方案1】:

您要做的最重要的事情是将您的集成放入一个单独的 maven 模块中,称为whatever-it(用于集成测试)。将 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>

添加执行块:

  <executions>
      <execution>
        <id>start-container</id>
        <phase>pre-integration-test</phase>
        <goals>
          <goal>start</goal>
          <goal>deploy</goal>
        </goals>
        <configuration>
          <deployer>
            <deployables>
              <deployable>
                <groupId>${project.groupId}</groupId>
                <artifactId>mod-war</artifactId>
                <type>war</type>
                <pingURL>http://localhost:9080/mod-war</pingURL>
                <pingTimeout>30000</pingTimeout>
                <properties>
                  <context>mod-war</context>
                </properties>
              </deployable>
            </deployables>
          </deployer>
        </configuration>
      </execution>

和关机部分:

      <execution>
        <id>stop-container</id>
        <phase>post-integration-test</phase>
        <goals>
          <goal>stop</goal>
        </goals>
      </execution>
    </executions>
  </plugin>

上面的配置描述了一个完整的集成测试周期,下载一个tomcat解包tomcat的分发部署一个war文件(依赖项目到tomcat),启动web应用程序,最后停止Tomcat。为了您的目的,您需要更改的是您没有启动阶段,因为您已经有一个正在运行的容器。 cargo documentation 中描述了如何执行此操作。最后,您必须将集成测试放入集成测试模块的 src/test/java 文件夹中,并且不要忘记配置 maven-surefire-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>

您可以查看完整示例here。对此的描述是here

【讨论】:

  • 感谢您的信息。这或多或少是我们最终做的事情(主要区别在于我们使用了一个已经在运行的远程 Tomcat,因此不需要启动/停止)。
猜你喜欢
  • 2015-07-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-11-03
  • 2023-03-05
  • 1970-01-01
相关资源
最近更新 更多