2013-05-22 3 views
0

다음 설치가 있습니다 : 일반적으로 webapp가 독립형 서버에 배포되고 MySQL 데이터베이스에 연결됩니다. 그러나 셀렌으로 응용 프로그램을 "자체 테스트"할 수있는 능력이 필요합니다. 따라서 mvn clean install에는 웹 서버에 대한 사용자 입력의 예가 될 수있는 임베디드 서버 (Jetty 7), Selenium Server 및 메모리 내장 데이터베이스 (HSQLDB)가 있습니다. 지금은 이미 설정 셀레늄/임베디드 서버 설치 사용 받는다는 플러그인 :통합 테스트를 실행할 때 다른 스프링 구성을로드하십시오.

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

(SRC/테스트/자원에 있습니다 서블릿 - 컨텍스트 text.xml) 하지만 셀레늄 테스트는 웹 애플리케이션을 실행할 때 여전히 기본 구성으로 시작 .

기본적으로 내가 이것을 사용하려는 때문에 다른 XML 파일을로드하기 위해 노력하고있어 : 대신 내 정상은 dataSource 선언의

<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 매개 변수화)을 사용하여이 문제를 해결했습니다. 매력처럼 작동합니다.

관련 문제