• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 使用 J2EE 和 STAF/STAX 實現全生命周期的自動化回歸測試(2)

    發表于:2012-03-16來源:IBM作者:楊銳 張沖 支雷點擊數: 標簽:自動化回歸測試;J2EE
    回頁首 準備測試環境 建立 Resource Pool 并使用 STAF/STAX 驅動 VM Slave 大型軟件均支持多種平臺,因此 回歸 測試就必須覆蓋軟件支持的各種情況。不可避免的

      回頁首

      準備測試環境

      建立 Resource Pool 并使用 STAF/STAX 驅動 VM Slave

      大型軟件均支持多種平臺,因此回歸測試就必須覆蓋軟件支持的各種情況。不可避免的,在一次回歸中需要用到多臺測試機。VMware 虛擬機是一種被廣泛使用的,支持多種操作系統的虛擬機解決方案軟件。它可以方便地保存和還原各種的系統狀態(Snapshot),可以大大降低配置測試環境的工作量,并且顯著減少測試環境帶來的問題。

      我們把一臺具有唯一主機名(Host Name)的虛擬機稱為一臺 Slave。為了方便的查詢和管理這些 Slave,我們在數據庫中建立了一個表作為資源池(Resource Pool)。這張表管理了所有 Slave 機器的標識(ID),主機名(HostName),狀態(State),用戶名(User)和密碼(Password)。

      其中 Slave 的狀態包含以下幾種:

      使用中(onjob)

      在線且空閑(online&free)

      離線(offline)

      不可用(no-available)

      我們使用 STAF/STAX 實現對 VM Slave 的自動地控制。這部分的 STAX 腳本如下:

      清單 1. 啟動 VM Slave 并還原 Snapshot

    				
    <stax>
    <function name="prepareVM">
    <function-list-args>
      <function-required-arg name="VMWareServer">VMWareServer</function-required-arg>
        <function-required-arg name="vmIP">vmIP</function-required-arg>
        <function-required-arg name="delayTime">delayTime</function-required-arg>
        <function-required-arg name="vmxFile">vmxFile</function-required-arg>
        <function-required-arg name="snapshotName">snapshotName</function-required-arg>
      </function-list-args>
      <sequence>
        <!-- Revert Slave to a saved snapshot-->
        <process name="'revertVM'">
          <location>VMWareServer</location>
          <command>'vmrun'</command>
          <parms>'revertToSnapshot %s %s' %(vmxFile,snapshotName)</parms>
        </process>
        <!-- Start VM -->
        <process name="'startVM'">
          <location>VMWareServer</location>
          <command>'vmrun'</command>
          <parms>'start %s' %(vmxFile)</parms>
        </process>
    
        <!-- Check if startVM cmd is finished normally -->
        <if expr="RC != 0">
          <throw exception="'eTerminateFunction'">'Failed to start VM'</throw>
        </if>
            
        <!-- Ping the target machine and ensure it open -->
        <timer duration="'10m'">
          <sequence>
          <script>pingRC = 1</script>
          <loop until="pingRC == 0">
            <sequence>
              <stafcmd name="'PingTargetMachine'">
                <location>vmIP</location>
                <service>'PING'</service>
                <request>'PING'</request>
              </stafcmd>
              <if expr="RC != 0">
                <sequence>
                  <stafcmd name="'delay'">
                    <location>'local'</location>
                    <service>'DELAY'</service>
                    <request>'DELAY %s' %(delayTime)</request>
                  </stafcmd>
                </sequence>
              <else>
                <sequence>
                  <log>'%s is opened' %(vmIP)</log>
                  <script>pingRC = 0</script>
                </sequence>
              </else>
            </if>
          </sequence>
        </loop>
      </sequence>
      </timer>
      
      <!-- If the Slave cannot ping within the given time -->
      <if expr="RC != 0">
        <throw exception="'systemException'">
          'Fail to start VM Slave, please do a further check!'
        </throw>
      </if>
      </sequence>
    </function>
    </stax>
    

      使用 STAF Java API 下載和安裝 test builds 和 testcase

      STAF Java API 是 STAF 提供的 Java 編程接口。它可以用來通過 Java 程序提交 STAF 命令或者注冊諸如 STAX,Event 和 Email 之類的服務。STAF 通過 JSTAF.jar 來提供 Java 支持,只要將此 jar 包導入 CLASSPATH 中就可以使用。用戶可以在 ..\STAFInstallFolder\bin\ 目錄下找到這個 jar 包。

      系統在自動啟動 VM Slave 并還原到我們需要的鏡像后,就需要下載和安裝待測試的軟件了。假設待測試的軟件安裝包以壓縮文件的形式存放在一個 FTP 服務器上,自動化測試框架通過 STAF Java API 提供自動下載、解壓和靜默安裝功能。所需代碼如下:

      清單 2. 測試軟件的自動下載和安裝

    				
    // 使用 STAF FTP 服務自動下載待測試軟件安裝包
    private boolean downESE(STAFHandle handler) { 
    
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing: downloading build file..."); 
        String stafcmd = "GET HOST " + GlobalVar.ftpURl + " URLPATH " + this.url 
            + " FILE " + this.localURL + "\\" + GlobalVar.clientFileName; 
        STAFResult stafResult = handler 
            .submit2(GlobalVar.clientURl, "ftp", stafcmd); 
        if (stafResult.rc != 0) { 
            db.updateRequestStatus(form.getRid(), 
                "Test stop:down build file failed!"); 
            return false; 
        } 
        System.out.println("down success"); 
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing:down build file successed!"); 
        return true; 
    } 
    
    // 使用 STAF Zip 服務自動解壓安裝包
    private boolean unzipESE(STAFHandle handler) { 
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing: unzipping ese file..."); 
        String stafcmd = "unzip zipfile " + this.localURL + "\\"
            + GlobalVar.clientFileName + " todirectory " + this.localURL; 
        STAFResult stafResult = handler 
            .submit2(GlobalVar.clientURl, "zip", stafcmd); 
        if (stafResult.rc != 0) { 
            db.updateRequestStatus(form.getRid(), 
                "Test stop:unzip ese file failed!"); 
            return false; 
        } 
        System.out.println("unzip success"); 
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing:unzip ese file successed!"); 
        return true; 
    } 
    
    // 使用 STAF Process 服務實現軟件的靜默安裝
    private boolean silentInstall(STAFHandle handler) { 
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing: installing db2 client..."); 
        String stafcmd = "start command " + this.localURL + GlobalVar.setupFile 
            + " /f /l " + GlobalVar.logFile + " /u "
            + generateScrips(this.form) + " /t " + GlobalVar.db2LogFile 
            + " /m wait returnstdout"; 
        STAFResult stafResult = handler.submit2(GlobalVar.clientURl, "process", 
            stafcmd); 
        if (stafResult.rc != 0) { 
            db.updateRequestStatus(form.getRid(), 
                "Test stop:install db2 client failed!"); 
            return false; 
        } 
        System.out.println("silent success"); 
        db.updateRequestStatus(form.getRid(), 
            "Test ongoing:install db2 client successed!"); 
        return true; 
    } 
    

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>