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

时间:2015-03-11 10:25:09

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

我希望Jetty在集成测试之前启动,以便我可以针对我的webapp运行我的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>

2 个答案:

答案 0 :(得分:0)

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

您必须使用maven-fail-safeplugin才能运行集成测试。这个插件有两个目标:integration-test&amp; 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>

希望有所帮助。

答案 1 :(得分:0)

我无法看到您的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 Testcases相同的端口(Selenium使用4444作为默认端口),例如默认端口8080或jetty插件中配置了<port>xy</port>的其他端口。在默认端口的情况下,它看起来像这样:

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