使用maven进行集成测试

时间:2013-08-20 11:37:52

标签: maven

我正在尝试创建类似集成测试的东西 - 我使用groovy发送请求并解析答案。我也想要启动jboss并自动部署.ear。使用货物插件我能够启动jboss。通过使用exec插件我试图执行将耳朵放到部署文件夹的perl脚本。下一阶段 - 执行groovy测试,但此阶段开始时无需等待部署耳朵。有可能让阶段等待服务器部署到jboss吗?我的pom:

<build>
    <plugins>
       <plugin>
          <groupId>org.codehaus.groovy.maven</groupId>
          <artifactId>gmaven-plugin</artifactId>
          <executions>
             <execution>
                <id>unpack-application-server</id>
                <phase>pre-integration-test</phase>
                <goals>
                   <goal>execute</goal>
                </goals>
                <configuration>
                   <source>${basedir}/src/main/script/appserver/unzip.groovy</source>
                   <defaults>
                      <installDirectory>${appserver.install.directory}</installDirectory>
                      <zipUrl>${appserver.zip.url}</zipUrl>
                   </defaults>
                </configuration>
             </execution>

             <execution>
                <id>prepare-application-server-configs</id>
                <phase>pre-integration-test</phase>
                <goals>
                   <goal>execute</goal>
                </goals>
                <configuration>
                   <source>${basedir}/src/main/script/appserver/${suffix}/postUnzipAction.groovy</source>
                </configuration>
             </execution>
          </executions>
       </plugin>
       <plugin>
          <groupId>org.codehaus.cargo</groupId>
          <artifactId>cargo-maven2-plugin</artifactId>

          <executions>
             <execution>
                <id>start-container</id>
                <phase>pre-integration-test</phase>
                <goals>
                   <goal>start</goal>
                </goals>
             </execution>
          </executions>

          <configuration>
             <wait>false</wait>
             <container>
                <containerId>${appserver.id}</containerId>
                <home>${appserver.home}</home>
                <timeout>6000000</timeout> <!--in ms-->
             </container>

             <configuration>
                <properties>
                   <cargo.servlet.port>${servlet.port}</cargo.servlet.port>
                   <cargo.rmi.port>${rmi.port}</cargo.rmi.port>
                   <!-- corresponds to -Djboss.bind.address=0.0.0.0 under jboss -->
                   <cargo.hostname>0.0.0.0</cargo.hostname>
                </properties>
             </configuration>
          </configuration>
       </plugin>

       <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <executions>
             <execution>
                <id>deploy-with-script</id>
                <phase>pre-integration-test</phase>
                <goals>
                   <goal>exec</goal>
                </goals>
                <configuration>
                   <executable>perl</executable>
                   <workingDirectory>.</workingDirectory>
                   <commandlineArgs>${deploy.pl.cmd} -x redeploy</commandlineArgs>
                </configuration>
             </execution>
          </executions>
       </plugin>
    </plugins>
 </build>

1 个答案:

答案 0 :(得分:0)

  1. 在集成测试阶段之前和之后设置并拆除服务器,类似:

    <executions>
        <execution>
            <id>start-tomcat</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>run</goal>
            </goals>
        </execution>
        <execution>
            <id>stop-tomcat</id>
            <phase>post-integration-test</phase>
            <goals>
                <goal>shutdown</goal>
            </goals>
        </execution>
    </executions>
    
  2. 将您的单元测试重命名为surefire跳过,但由maven-failsave-plugin执行到* IT.java:http://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html