代码之家  ›  专栏  ›  技术社区  ›  ses

Maven在集成测试阶段运行码头

  •  5
  • ses  · 技术社区  · 11 年前

    我使用 failsafe 插件。

    所以当我打字时 mvn failsafe:integration-test 它是我的集成测试的明星(这很棒)。

    但我想要我的 jetty server 开始于 pre-integration 然后进行阶段。我该怎么办?

    (我不想发射 mvn verify 因为它涉及整个循环运行,但是 mvn故障保护:集成测试 -看起来应该是这样的)

    有两个插件:

    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-failsafe-plugin</artifactId>                                                              <!-- for starting jetty for integration tests -->
        <version>2.16</version>
        <executions>
            <execution>
                <id>integration-test</id>
                <goals>
                    <goal>integration-test</goal>
                </goals>
            </execution>
            <execution>
                <id>verify</id>
                <goals>
                    <goal>verify</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>${jetty.version}</version>
        <configuration>
            <!--<jettyConfig>${project.basedir}/src/main/resources/config/jetty9.xml</jettyConfig>-->
            <stopKey>STOP</stopKey>
            <stopPort>9999</stopPort>
            <stopWait>5</stopWait>
            <scanIntervalSeconds>5</scanIntervalSeconds>
            <scanTargets>
                <scanTarget>${project.basedir}/src/main</scanTarget>
                <scanTarget>${project.basedir}/src/test</scanTarget>
            </scanTargets>
            <contextXml>${project.basedir}/src/test/resources/jetty-context.xml</contextXml>
            <webAppConfig>
                <contextPath>/${project.artifactId}-${project.version}</contextPath>
            </webAppConfig>
        </configuration>
    
        <executions>
            <execution>
                <id>start-jetty</id>
                <phase>pre-integration-test</phase>                                                         <!-- In the pre-integration-test phase the Jetty server will be started -->
                <goals>
                    <goal>run-exploded</goal>
                </goals>
                <configuration>
                    <scanIntervalSeconds>0</scanIntervalSeconds>
                    <daemon>true</daemon>
                </configuration>
            </execution>
            <execution>
                <id>stop-jetty</id>
                <phase>post-integration-test</phase>                                                        <!-- in the "post-integration-phase" it will be stopped -->
                <goals>
                    <goal>stop</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    
    2 回复  |  直到 10 年前
        1
  •  5
  •   Community Mohan Dere    5 年前

    这是jetty和maven故障保护插件使用手册:

    Maven Failsafe Plugin – Usage

    它提供了将Jetty集成到集成测试生命周期中的示例配置。

    码头在 pre-integration-test 相位,并在v期间停止 post-integration-test 阶段

    <plugin>
        <groupId>org.mortbay.jetty</groupId>
        <artifactId>maven-jetty-plugin</artifactId>
        <version>6.1.16</version>
        <executions>
          <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <scanIntervalSeconds>0</scanIntervalSeconds>
              <daemon>true</daemon>
            </configuration>
          </execution>
          <execution>
            <id>stop-jetty</id>
            <phase>post-integration-test</phase>
            <goals>
              <goal>stop</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    

    但是,它还特别建议您使用 verify 相位:

    建议不要直接调用 集成前测试、集成测试或集成后测试阶段 而是通过指定验证来运行集成测试 阶段[...]

    这允许您设置集成测试 在预集成测试阶段,运行 集成测试阶段的集成测试,彻底分解 集成后测试期间的集成测试环境 最后检查集成测试结果并失败之前的阶段 如果需要,构建。

        2
  •  2
  •   froderik    11 年前

    我更喜欢在测试用例中以编程方式启动jetty。主要原因如下:

    • 测试变得独立,不依赖于maven配置
    • 可以运行测试 按原样 在任何IDE中