成就夢想

            BlogJava :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理 ::
            21 隨筆 :: 22 文章 :: 6 評論 :: 0 Trackbacks
          <2012年4月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          常用鏈接

          留言簿

          隨筆分類(4)

          隨筆檔案(8)

          文章分類(13)

          文章檔案(10)

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

                  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)  編輯  收藏 所屬分類: 項目管理

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


          網站導航:
           
          主站蜘蛛池模板: 汾阳市| 呼和浩特市| 敖汉旗| 康保县| 米易县| 泽普县| 高邑县| 福贡县| 镇坪县| 平顶山市| 德庆县| 崇明县| 静安区| 滦南县| 湾仔区| 徐闻县| 青铜峡市| 分宜县| 白玉县| 新闻| 新蔡县| 安顺市| 新晃| 孟连| 聊城市| 南澳县| 楚雄市| 历史| 沾益县| 泽普县| 崇左市| 武宣县| 萍乡市| 辽阳市| 永嘉县| 阜城县| 桑日县| 上栗县| 垫江县| 郯城县| 房产|