2013-05-22 149 views
0

我有以下設置:通常我的webapp將部署在獨立服務器上並連接到MySQL數據庫。不過,我希望能夠使用Selenium「自我測試」應用程序。因此,在mvn clean install中,將會有嵌入式服務器(Jetty 7),Selenium Server和內存數據庫(HSQLDB),這些數據庫允許執行一些操作(例如webapp的用戶輸入)。 現在我已經設置硒/嵌入式服務器設置使用Maven插件:運行集成測試時加載不同的彈簧配置

<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的上下文text.xml位於的src /測試/資源) 但是當Selenium測試運行Web應用程序仍然開始默認配置。

我試圖加載不同的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> 

,而不是我的正常的數據源的聲明。

回答

0

也許這對某些人會有幫助。我最終使用Maven概要文件(用於集成測試和生產構建的單獨概要文件)和過濾(針對導入dataSource.xml或dataSourceIntegrationTesting.xml的參數化servlet-context.xml)解決了此問題。奇蹟般有效。

相關問題