2

我有一个 Maven 项目,它为另一个 Web 应用程序执行集成测试。此应用程序在 tomcat 容器中部署和启动。

对此的配置在“cargo-maven2-plugin”中完成:

 <plugin>
  <groupId>org.codehaus.cargo</groupId>
  <artifactId>cargo-maven2-plugin</artifactId>
  <configuration>
   <wait>false</wait>
   <configuration>
    <type>standalone</type>
    <properties>
     <cargo.hostname>${itest.hostname}</cargo.hostname>
     <cargo.protocol>${itest.protocol}</cargo.protocol>
     <cargo.servlet.port>${itest.port}</cargo.servlet.port>
     <cargo.servlet.uriencoding>UTF-8</cargo.servlet.uriencoding>
     <cargo.jvmargs>-Xmx1024m</cargo.jvmargs>
    </properties>
   </configuration>
   <container>
    <containerId>tomcat6x</containerId>
    <home>${TEST_TOMCAT_HOME}</home>
   </container>
   <deployer>
    <deployables>
     <deployable>
      <groupId>de.apllicationundertest</groupId>
      <artifactId>apllicationundertest</artifactId>
      <type>war</type>
      <!--
       This will test if the app is ready an throw an exception if
       the integration tests start before deployment is finished
      -->
      <pingURL>${itest.protocol}://${itest.hostname}:${itest.port}/${itest.web.context}/main.html 
      </pingURL>
      <pingTimeout>120000</pingTimeout>
      <!--  Setting our context for the integration tests -->
      <properties>
       <context>${itest.web.context}</context>
      </properties>
     </deployable>
    </deployables>
   </deployer>
  </configuration>
  <executions>
   <execution>
    <id>start-container</id>
    <phase>pre-integration-test</phase>
    <goals>
     <goal>start</goal>
     <goal>deploy</goal>
    </goals>
   </execution>
   <execution>
    <id>stop-container</id>
    <phase>post-integration-test</phase>
    <goals>
     <goal>stop</goal>
    </goals>
   </execution>
  </executions>
 </plugin>

正在测试的(web-)应用程序作为依赖项集成在我的集成测试项目的 pom.xml 中,因此我没有绝对或相对的战争路径。

我的问题是在我的程序运行期间我无法控制 tomcat 容器。虽然我的测试场景需要在一些测试之间停止和重新启动容器(以及重新部署被测应用程序),但 fe 用于检查容器停止后是否仍有一些活动线程或是否仍有一些元素我在缓存中的应用程序,...

  1. 我想在 java 之外配置容器的启动和停止,最好在 pom.xml 中。那可能吗?
  2. 我可以指定某些单元测试需要重新启动并执行吗?如何?
4

2 回答 2

0

我想在 java 之外配置容器的启动和停止,最好在 pom.xml 中。那可能吗?

您可以从 Maven 做的就是您当前正在做的事情:分别在预集成测试和集成测试后阶段启动和停止货物。

我可以指定某些单元测试需要重新启动并执行吗?如何?

不,这是不可能的。Maven 没有这种粒度,也没有为此提供任何挂钩。如果这确实是您需要的,您有两种选择:

  • 就像我在上一个答案中描述的那样,从 Java 控制容器。
  • 将测试放在单独的 Maven 模块中(以便 Maven 将为每个模块启动和停止您的容器)。
于 2010-02-10T14:38:31.100 回答
0

我认为这是不可能的,因为启动容器是分阶段完成的pre-integration-test。为什么需要在重新启动的服务器中运行特定的测试?如果可能,请尝试重写您的测试(进行清理)。

我想在 java 之外配置容器的启动和停止,最好在 pom.xml 中。那可能吗?

如果您几乎不需要这个,您可以尝试将单独测试的配置放在专用配置文件中。每个配置文件都将包含 cargo 和 surefire/failsafe 插件的配置。

我可以指定某些单元测试需要重新启动并执行吗?如何?

您可以指定应该运行的测试。查看surefire/故障安全插件配置

<plugins>
  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-failsafe-plugin</artifactId>
    <version>2.5</version>
    <configuration>
      <includes>
        <include>Sample.java</include>
      </includes>
    </configuration>
    <executions>
      <execution>
        <id>integration-test</id>
        <phase>integration-test</phase>
        <goals>
          <goal>integration-test</goal>
        </goals>
      </execution>
      <execution>
        <id>verify</id>
        <phase>verify</phase>
        <goals>
          <goal>verify</goal>
        </goals>
      </execution>
    </executions>
  </plugin>
</plugins>
于 2010-02-10T10:50:44.127 回答