2013-11-10 98 views
1

現在,我通過行家開始分別嵌入的Tomcat:自動啓動/停止Web服務器測試

mvn tomcat7:run 

再運行mvn test目標。 我的問題是我可以配置maven爲了做到這一點自動? tomcat必須在所有測試運行之前啓動,然後停止。

爲Tomcat插件以下Maven配置用於:

 <plugins> 
     <plugin> 
      <groupId>org.apache.tomcat.maven</groupId> 
      <artifactId>tomcat7-maven-plugin</artifactId> 
      <version>2.1</version> 
      <configuration> 
       <path>/SpringMvcExample</path> 
       <url>http://localhost:8080/manager/text</url> 
       <server>tomcat7</server> 
      </configuration> 
     </plugin> 
    </plugins> 

我試圖更新插件配置:

<plugin> 
     <groupId>org.apache.tomcat.maven</groupId> 
     <artifactId>tomcat7-maven-plugin</artifactId> 
     <version>2.1</version> 
     <configuration> 
      <path>/SpringMvcExample</path> 
      <url>http://localhost:8080/manager/text</url> 
      <server>tomcat7</server> 
     </configuration> 
     <executions> 
      <execution> 
       <id>start-tomcat</id> 
       <phase>pre-integration-test</phase> 
       <goals> 
        <goal>run</goal> 
       </goals> 
      </execution> 
      <execution> 
       <id>stop-tomcat</id> 
       <phase>post-integration-test</phase> 
       <goals> 
        <goal>shutdown</goal> 
       </goals> 
      </execution> 
     </executions> 
    </plugin> 

但它並沒有幫助

回答

2
 attach tomcat:run to pre-integration-test 
     attach tomcat:shutdown to post-integration-test 
Below is the code snippet. 
    <plugin> 
     <groupId>org.apache.tomcat.maven</groupId> 
     <artifactId>tomcat7-maven-plugin</artifactId> 
     <version>2.1</version> 
     <executions> 
      <execution> 
      <id>tomcat-run</id> 
      <goals> 
       <goal>run-war-only</goal> 
      </goals> 
      <phase>pre-integration-test</phase> 
       <configuration> 

        <fork>true</fork> 
       </configuration> 

      </execution> 
      <execution> 
      <id>tomcat-shutdown</id> 
      <goals> 
       <goal>shutdown</goal> 
      </goals> 
      <phase>post-integration-test</phase> 
      </execution> 
     </executions> 
     </plugin> 
+0

請說明這些陳述的放置位置? – Alexandr

+0

已更新我的帖子 – Sanj

+0

有幾個問題。你使用哪個Maven版本?在配置中 - url和server在我的編輯器中是紅色的,看起來元素在這裏是不允許的。第二個:如何指定測試是整合?使用的類的名稱:SimpleViewControllerSeleniumTest – Alexandr