2013-05-22 2 views
0

У меня есть следующая настройка: обычно мой webapp будет развернут на автономном сервере и подключиться к базе данных MySQL. Однако я хочу, чтобы «самотестировать» приложение с Selenium. Таким образом, во время mvn clean install будет встроен сервер (Jetty 7), сервер Selenium и база данных в памяти (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{ 

(сервлет-контекстный-text.xml находится в SRC/тест/ресурсы) но когда Selenium тесты запустить веб-приложение по-прежнему началась с настройками по умолчанию ,

Я пытаюсь загрузить другой файл 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.

ответ

0

Возможно, кому-то это поможет. Я решил эту проблему, используя профили Maven (отдельные профили для тестирования интеграции и сборки) и фильтрацию (параметризовал мой servlet-context.xml в отношении импорта либо dataSource.xml, либо dataSourceIntegrationTesting.xml). Работает как шарм.

Смежные вопросы