成就夢想

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            21 隨筆 :: 22 文章 :: 6 評論 :: 0 Trackbacks
                  web應用集成測試的時候,各位還需要啟動web容器,然后打開瀏覽器,輸入ulr,然后看到瀏覽器的輸出嗎?

          下面我們用maven做到自動化!


           

          我們利用maven的生命周期和jetty插件來實現。

           

          下面描述下做的自動化web集成測試實現的原理。

          1,在生命周期pre-integration-test啟動jetty容器

          2,在生命周期integration-test中測試我們寫的***IT.java類

          3,在post-integration-test shutdow jetty容器。

          在pom.xml中加入代碼如下:

          <profiles>
                  
          <profile>
                      
          <id>ittest</id>
                      
          <build>
                          
          <plugins>
                              
          <plugin>
                                  
          <groupId>org.apache.maven.plugins</groupId>
                                  
          <artifactId>maven-surefire-plugin</artifactId>
                                  
          <executions>
                                      
          <execution>
                                          
          <id>run-integration-test</id>
                                          
          <phase>integration-test</phase>
                                          
          <goals>
                                              
          <goal>test</goal>
                                          
          </goals>
                                          
          <configuration>
                                              
          <includes>
                                                  
          <include>**/*IT.java</include>
                                              </includes>
                                          </configuration>
                                      </execution>
                                  </executions>
                              </plugin>
                              <plugin>
                                  <groupId>org.mortbay.jetty</groupId>
                                  <artifactId>maven-jetty-plugin</artifactId>
                                  <version>6.1.26</version>
                                  <configuration>
                                      <contextPath>/</contextPath>
                                      <stopPort>9966</stopPort>
                                      <stopKey>stop-jetty-for-it</stopKey>
                                      <connectors>
                                          <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
                                              <port>6211</port>
                                          </connector>
                                      </connectors>
                                  </configuration>

                                  <executions>
                                      <execution>
                                          <id>start-it-jetty</id>
                                          <phase>pre-integration-test</phase>
                                          <goals>
                                              <goal>run</goal>
                                          </goals>
                                          <configuration>
                                              <daemon>true</daemon>
                                          </configuration>
                                      </execution>
                                      <execution>
                                          <id>stop-it-jetty</id>
                                          <phase>post-integration-test</phase>
                                          <goals>
                                              <goal>stop</goal>
                                          </goals>
                                      </execution>
                                  </executions>
                              </plugin>
                          </plugins>
                      </build>
                  </profile>
              </profiles>

           

          然后就可以編寫測試用例了

           

           步驟如下:

          1,定義一個以此命名的****IT的測試類(integration test縮寫), 在里面華麗的寫好你的測試邏輯。

          再此不舉例了,主要一個思路可以用httpclint來實現里面的測試代碼。

          2,然后 執行 mvn clean post-integration-test -Pittest

          好了 就可以看到我們測試用例是否通過。

          建議:以上的代碼可以加入到父類的pom中,以后繼承此父pom后,只需要按以上2步,就可以做到web應用測試自動化了。

           



          posted on 2012-04-21 11:57 iamct 閱讀(3126) 評論(0)  編輯  收藏 所屬分類: 項目管理

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 彰武县| 乌拉特后旗| 万山特区| 常德市| 峡江县| 丁青县| 平昌县| 保亭| 元谋县| 巴彦淖尔市| 香河县| 乐清市| 托里县| 濮阳县| 昌江| 太白县| 稻城县| 芦山县| 潢川县| 日土县| 鄂温| 勐海县| 平江县| 漳浦县| 鸡泽县| 黄陵县| 诸暨市| 达拉特旗| 盐池县| 湄潭县| 大石桥市| 石楼县| 重庆市| 玛多县| 东明县| 抚宁县| 嘉善县| 杭州市| 文登市| 临泽县| 孙吴县|