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

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

  • <strong id="5koa6"></strong>
    • 軟件測試技術
    • 軟件測試博客
    • 軟件測試視頻
    • 開源軟件測試技術
    • 軟件測試論壇
    • 軟件測試沙龍
    • 軟件測試資料下載
    • 軟件測試雜志
    • 軟件測試人才招聘
      暫時沒有公告

    字號: | 推薦給好友 上一篇 | 下一篇

    使用自定義代碼對數據池進行隨機訪問

    發布: 2007-4-29 00:30 | 作者: R | 來源: IBM | 查看: 138次 | 進入軟件測試論壇討論

    領測軟件測試網 為了更加穩健的javascript:;" onClick="javascript:tagshow(event, '%B2%E2%CA%D4');" target="_self">測試,可以用自定義代碼使 Performance Tester 隨機化。目前,Performance Tester 數據池中的元素只能按照順序進行訪問。這篇文章討論了作者如何創建自定義的 Performance Tester 代碼,并用隨機數據訪問來實現數據池。這篇文章提供的了 RPTDataPool 類,以及如何實現它的詳細說明。

        注意:這篇文章適用于 IBM® Rational® Performance Tester Version 6.1.2.002

        好的測試不僅僅是重復執行相同的動作。為了更好的模擬實際用戶的動作,測試人員可以利用IBM Rational Performance Tester中的數據池。這是遠超出使用靜態記錄測試的一步,因為它允許測試為每個執行來選擇不同的變量。例如,無論什么時候應用軟件要求用戶輸入搜索條件,比如一個電影的名字,一個標題或者標題的一個部分都可以從數據池中選擇。

        目前Rational Performance Tester數據池僅僅是順序存儲。在這個電影搜索的例子中,每次你運行這個測試時,相同電影名稱的搜尋都是以相同的順序來進行處理的。通過對要搜索的標題進行隨機選擇,可以提高測試的穩健性。

        數據池文本文件

        在i5/OS系統測試環境中,IBM測試自動化小組自從2004年就一直在將Mercury');" target="_self">Mercury LoadRunner');" target="_self">LoadRunner的腳本轉換到Rational Performance Tester。為了隨機化i5/OS測試的變量選擇,我們創建了一個Rational Performance Tester自定義代碼的包,來對數據池中的元素進行隨機存儲。這個執行一點都沒有用到Rational Performance Tester數據池的特性。相反,Rational Performance Tester DataPool 類讀取的文本文件中包含要使用的數據池條目。

        這個將選擇元素隨機化的數據池文件是一個每行僅包含一個元素的純文本文件。用Rational Performance Tester來實現它的一個簡單的方法,就是為測試項目的文本文件創建一個數據池文件夾。一個文件輸出包括這些文本文件,因為它們被包含在Rational Performance Tester項目中。當轉換Mercury LoadRunner腳本時,你可以通過LoadRunner數據文件來實現。

    RPTDataPool類

        這個文本數據的文件名傳給創建者,整個文件在首次訪問嘗試時就被讀取進入了 Java™ Vector 對象。為了從這個數據池中隨機重新找到一個條目,可以使用getaDataPoolItem 方法。(參見列表1。)

    注意事項

        記住整個文件在測試的開始就已被讀入存儲器是十分重要的。巨大的數據池將會用到大量的內存,這將會降低加載和Rational Performance啟動的速度。巨大的Rational Performance Tester測試數據池也會發生類似的情況。

        你可以使用每行包含多個元素的數據池,但是用戶必須在這個測試的自定義代碼中增加一些功能來取出單個元素。


        列表1. getaDataPoolItem 方法
        
    import .io.*;
    import .util.Vector;
    public class RPTDataPool {
        private boolean DataPoolIsLoaded = false;
        private String DataPoolFileName;
        private Vector DataPool;
        private int DataPoolCount = 0;
     
        public RPTDataPool( String fileName )  {
            DataPoolFileName = fileName;
            DataPool = new Vector();
            DataPoolCount = fillVector( DataPoolFileName, DataPool);
            DataPoolIsLoaded = true;
            }
      
        public String getaDataPoolItem(  )  {
            if( !DataPoolIsLoaded ) {
                //System.out.println("loading:" + DataPoolFileName);
                DataPoolIsLoaded = true;
            }
            return (String) DataPool.elementAt((int)
              (Math.floor(Math.random() * (DataPoolCount))));
        }
       
        private int fillVector( String fileName, Vector FileLines) {
            // take the Datapool file and read it into a Vector
            // do this only once per test
            int fileLineCounter = 0;
           
            BufferedReader brInReader = null;
           
            // read from the file
            // try to setup a buffered reader and open the file
            try  { brInReader = new BufferedReader(new FileReader(fileName));}
            catch(Exception error)
            {
          //System.out.println("Error Opening DataPool File: " + error);
          return 0;
      }
      
      // read the file and place the lines in an array
      // get the first line of the file
      String sInLine = ReadLine(brInReader);
      
      // read through the file
      while (sInLine != null)
      {
          //System.out.println("Storing '"+ sInLine+"'");
          FileLines.addElement(sInLine);
         
          // read the next line
          sInLine = ReadLine(brInReader);
         
          fileLineCounter++;
      }
      
      // At this point, the FileLines Vector has all the lines
      from the file and fileLineCounter
      
      // indicates the max index value for the array
      return fileLineCounter;
      }
      
      // ReadLine
      // This method will read a line from a given file and return the string value
      // ********************************************************************************
      
      private String ReadLine(BufferedReader brReader) {
          String sReadLine = "";
          try  {  sReadLine = brReader.readLine();}
          catch (IOException error)
          {//System.out.println("DataPool.test Read Error: " + error);}
         
          return sReadLine;
      }
      // end of Read
      }


        在測試中實例化數據池對象

        為Rational Performance Tester測試項目創建一個特殊的類來實例化這個數據池的對象。這里,用MovieSearchDataPools來舉例說明,這個電影搜索項目需要三個不同的數據池(請看列表2)


    列表 2. MovieSearchDataPools 例子
        

    public class MovieSearchDataPools {
        static RPTDataPool Titles =
            new RPTDataPool("C:\\Workloads\\ MovieSearch\\ Datapools\\MovieTitles.txt" );
           
        static RPTDataPool Directors =
            new RPTDataPool("C:\\Workloads\\ MovieSearch\\ Datapools\\MovieDirectors.txt" );
           
        static RPTDataPool Actors =
            new RPTDataPool("C:\\Workloads\\ MovieSearch\\ Datapools\\MovieActors.txt" );
        }


        使用自定義代碼從一個數據池中取回數據

        要取回一個元素,在一個自定義代碼模塊中使用getaDataPoolItem方法。用這個電影搜索的例子來取回一個任意電影的標題名稱,如列表3所示。


    列表 3: 使用 getaDataPoolItem 方法
        
    package test;

    import com.ibm.rational.test.lt.kernel.services.ITestExecutionServices;

    public class GenerateRandomTitle implements
        com.ibm.rational.test.lt.kernel.custom.ICustomCode2 {
       
        /**
        * Instances of this will be created using the no-arg constructor.
        */
        public GenerateRandomTitle() { } 
       
        /**
        * For description of ICustomCode2 and ITestExecutionServices interfaces,
        * see doc located at 

    /rpt_prod/eclipse/plugins/com.ibm.rational.test.lt.kernel_/pubdoc
        */
       
    public String exec(ITestExecutionServices tes, String[] args) {
        return MovieSearchDataPools.Titles.getaDataPoolItem();
        }
       
    }


        你可以使用來自搜索電影的HTTP請求中的自定義代碼模塊中的輸出結果。


    延伸閱讀

    文章來源于領測軟件測試網 http://www.kjueaiud.com/


    軟件測試技術文章排行榜
    軟件測試技術分類最新內容
    關于領測軟件測試網 | 領測軟件測試網合作伙伴 | 廣告服務 | 投稿指南 | 聯系我們 | 網站地圖 | 友情鏈接
    版權所有(C) 2003-2010 TestAge(領測軟件測試網)|領測國際科技(北京)有限公司|軟件測試工程師培訓網 All Rights Reserved
    北京市海淀區中關村南大街9號北京理工科技大廈1402室 京ICP備2023014753號-2
    技術支持和業務聯系:info@testage.com.cn 電話:010-51297073

    軟件測試 | 領測國際ISTQBISTQB官網TMMiTMMi認證國際軟件測試工程師認證領測軟件測試網

    老湿亚洲永久精品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>