java - 无法在预集成测试阶段启动 Jetty

标签 java maven selenium embedded-jetty maven-jetty-plugin

我希望 Jetty 在集成测试之前启动,以便我可以针对我的 Web 应用程序运行 Selenium 集成测试。但是,当我运行 mvn verify 时,Jetty 未启动,Selenium 测试自然会失败。任何想法有什么问题吗?

<plugin>
    <groupId>org.eclipse.jetty</groupId>
    <artifactId>jetty-maven-plugin</artifactId>
    <version>9.3.0.M1</version>
    <configuration>
        <webApp>
            <contextPath>/</contextPath>
        </webApp>
    </configuration>
    <executions>
        <execution>
            <id>start-jetty</id>
            <phase>pre-integration-test</phase>
            <goals>
                <goal>start</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>

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-surefire-plugin</artifactId>
    <version>2.17</version>
    <configuration>
        <skip>true</skip>
    </configuration>
    <executions>
        <execution>
            <id>unit-tests</id>
            <phase>test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <skip>false</skip>
                <excludes>
                    <exclude>**/*IntegrationTest.java</exclude>
                </excludes>
            </configuration>
        </execution>
        <execution>
            <id>integration-tests</id>
            <phase>integration-test</phase>
            <goals>
                <goal>test</goal>
            </goals>
            <configuration>
                <skip>false</skip>
                <includes>
                    <include>**/*IntegrationTest.java</include>
                </includes>
            </configuration>
        </execution>
    </executions>
</plugin>

最佳答案

您使用了运行单元测试的maven-surefire-plugin。但就您而言,您想要运行集成测试。

您必须使用maven-fail-safeplugin为了运行集成测试。这个插件有两个目标:integration-test & verify,集成在maven生命周期中:

  • 预集成测试
  • 集成测试
  • 集成后测试
  • 验证

所以在你的情况下使用类似的东西:

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

希望有帮助。

关于java - 无法在预集成测试阶段启动 Jetty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28984032/

相关文章:

java - 如何在 Java 中创建一个不同时运行某些任务的线程池?

java - 单击另一个 Android 应用程序中的 x 和 y 位置

java - 与 Jersey 和 JSR 相关的 JAX-RS

Maven 快照存储库与发布存储库

java - 如何通过 Selenium 和 Java 使用 AShot 库截取整页截图

java - Hibernate:如何将多个连接表映射到Java对象(用户的书籍列表)

java - 如何比较日期和时间?

java - 运行 Maven 构建时如何访问 JAR 中的文件

java - selenium webdriver java 下拉框

node.js - 覆盖 Date 构造函数执行脚本