【问题标题】:Not able to start Jetty in pre-integration-test phase无法在预集成测试阶段启动 Jetty
【发布时间】:2015-05-13 02:09:31
【问题描述】:

我希望在集成测试之前启动 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>

【问题讨论】:

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


    【解决方案1】:

    您使用了运行单元测试的maven-surefire-plugin。但在您的情况下,您想要运行集成测试。

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

    • pre-integration-test
    • integration-test
    • post-integration-test
    • verify

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

    <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>
    

    希望对您有所帮助。

    【讨论】:

    • 我也试过了,但结果相同 - 集成测试将开始,但 Jetty 不会。
    • 你能分享一下控制台输出吗?
    【解决方案2】:

    我看不出您的jetty-maven-plugin 配置有什么问题,但是您如何处理 Selenium 配置?你有那个方向的插件配置吗?:

    <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>selenium-maven-plugin</artifactId>
        <version>${your.selenium.version}</version>
        <executions>
            <execution>
                <id>start-selenium</id>
                <phase>pre-integration-test</phase>
                <goals>
                    <goal>start-server</goal>
                </goals>
                <configuration>
                    <background>true</background>
                </configuration>
            </execution>
            <execution>
                <id>stop-selenium</id>
                <phase>post-integration-test</phase>
                <goals>
                    <goal>stop-server</goal>
                </goals>
            </execution>
        </executions>
    </plugin>
    

    然后确保您的 Jetty 服务器与您的 Selenium 测试用例具有相同的端口(Selenium 使用 4444 作为默认端口),例如默认端口 8080 或在 jetty 插件中使用 &lt;port&gt;xy&lt;/port&gt; 配置的另一个端口。在默认端口的情况下,它看起来像这样:

    new DefaultSelenium(“localhost”,4444,“*firefox”,“http://localhost:8080″);
    

    【讨论】:

    • 我没有使用 Selenium 插件。浏览器启动并导航到正确的地址并使用正确的端口,但由于启动 Jetty 失败,因此没有应用程序运行。
    • 好吧,在这种情况下你显然没有错过 Selenium 插件配置:) “因为启动 Jetty 失败”我假设你不是在谈论实际的异常或构建失败,而是服务器的状态不是 beeing startet - 我建议将集成测试前/集成后阶段的相关部分添加到问题中。 (我担心我不会再提供帮助,但我会坚决地回来查看)。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-12-26
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多