我有以下设置:通常我的 webapp 将部署在独立服务器上并连接到 MySQL 数据库。但是我希望能够使用 Selenium “自我测试”应用程序。因此,在mvn clean install期间,将有嵌入式服务器(Jetty 7)、Selenium 服务器和内存数据库(HSQLDB),它们将允许执行一些操作(例如 webapp 的用户输入)。现在我已经使用 maven 插件设置了 Selenium/嵌入式服务器设置:
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.10</version>
<configuration>
<!-- Log to the console. -->
<requestLog implementation="org.mortbay.jetty.NCSARequestLog">
<!-- This doesn't do anything for Jetty, but is a workaround for a Maven bug
that prevents the requestLog from being set. -->
<append>true</append>
</requestLog>
</configuration>
</plugin>
<!--
*******************************************************
Start selenium-server before the integration test start
*******************************************************
-->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>selenium-maven-plugin</artifactId>
<executions>
<execution>
<id>start-selenium-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start-server</goal>
</goals>
<configuration>
<background>true</background>
<logOutput>true</logOutput>
<multiWindow>true</multiWindow>
</configuration>
</execution>
<execution>
<id>stop-selenium-server</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop-server</goal>
</goals>
</execution>
</executions>
</plugin>
<!-- ********************************************************
Force to run the testcases in the integration-test phase
******************************************************** -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<!-- Skip the normal tests, we'll run them in the integration-test phase -->
<skip>true</skip>
</configuration>
<executions>
<execution>
<phase>integration-test</phase>
<goals>
<goal>test</goal>
</goals>
<configuration>
<skip>false</skip>
</configuration>
</execution>
</executions>
</plugin>
<!-- ***********************************************************
Deploy the war in the embedded jetty of cargo2-maven-plugin
*********************************************************** -->
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.4.1-SNAPSHOT</version>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-container</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
<configuration>
<wait>false</wait>
<container>
<containerId>jetty7x</containerId>
<type>embedded</type>
</container>
</configuration>
</plugin>
它工作得很好。不幸的是,当应用程序部署在嵌入式服务器上以进行集成测试时,我在尝试使 Spring/Maven 使用不同的 XML 配置文件时遇到了一些问题。
我尝试使用:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:servlet-context-test.xml" })
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class TestWebapp extends SeleneseTestCase{
(servlet-context-text.xml位于src/test/resources)但是当 Selenium 测试运行时,webapp 仍然以默认配置启动。
我正在尝试加载不同的 xml 文件,因为我基本上想使用它:
<jdbc:embedded-database id="dataSource">
<jdbc:script location="classpath:sql/schema.sql"/>
<jdbc:script location="classpath:sql/fk.sql"/>
<jdbc:script location="classpath:sql/data.sql"/>
</jdbc:embedded-database>
而不是我正常的 dataSource 声明。