2010-07-23 25 views
2

我對Rational Functional Tester(Java)相當陌生,但我有一個很大的空白。我有一個在敏捷開發環境中的應用程序,因此一些屏幕可以在新界面聯機時顯示。Rational Functional Tester - 如何獲取從父腳本調用的腳本以使用父級的數據池?

由於這個原因,我試圖模塊化我的測試腳本。例如:我想要一個登錄腳本,一個搜索腳本和一個註銷腳本。

我會再縫合在一起,這些(僞代碼)

Call Script components.security.Login; 
Call Script components.search.Search; 
//verification point 
Call Script components.security.Logout; 

通過打破測試腳本爲離散塊(功能單元),我相信我將能更好地適應變化。如果登錄腳本發生變化,我會修復或重新記錄一次爲應用程序中的每個腳本。

然後我會調用該腳本,例如「TestSituation_001」。它需要引用幾個不同的數據池。在這個實例中,一個用戶數據池(而不是一個超級用戶數據池)和一個TestSituation_001數據池,或者可能還有一些其他數據池。驗證點將使用情景數據池進行檢查。

現在,這就是我將如何在理想世界中做到這一點。目前困擾着我的是,看起來我需要做一些完全不同的事情來讓孩子的腳本繼承父母。

所以我的問題是:

  1. 爲什麼不子腳本只是繼承調用腳本的數據池?
  2. 我該如何讓他們做到這一點?
  3. 我對這種工作方式做出了糟糕的假設嗎?
  4. 如果#3是真的,那我該如何做得更好?

作爲一個方面說明,我不介意盜用Java的某些部分以使其工作。

謝謝!

回答

2

我解決了我自己的問題。對於那些你誰是好奇,檢查了這一點:

public abstract class MyTestHelper extends RationalTestScript 
{ 

    protected void useParentDataPool() { 
     if(this.getScriptCaller() != null) { 
      IDatapool dp = this.getScriptCaller().getDatapool(); 
      IDatapoolIterator iterator = DatapoolFactory.get().open(dp, ""); 
      if(dp != null && iterator != null) { 
       //if the datapool is not null, substitute it for the current data pool 
       this.dpInitialization(dp, iterator); 
      }       
     } 
    } 

} 

這將使用相同的迭代器了。快樂的狩獵......

實際上,經過一些反思之後,我提出了一種方法,可以讓任何給定的腳本使用Root調用腳本的DataPool。再次,快樂的狩獵給那些需要它的人...

/* 
* preconditions: there is a parent caller 
* postconditions: the current script is now using the same datapool/datapool iterator as the root script 
*/ 
protected void useRootDataPool() { 
    //if there is no parent, then this wouldn't work so return with no result; 
    if(this.getScriptCaller() == null) return; 

    //assume that we're at the root node to start 
    RationalTestScript root = this; 
    while(root.getScriptCaller() != null) { 
     root = root.getScriptCaller(); 
    } 

    //if this node is the root node, no need to continue. the default attached datapool will suffice. 
    if(this.equals(root)) return; 

    //get the root's data pool (which would be the parent's parent and so on to the topmost) 
    IDatapool dp = root.getDatapool(); 
    if(dp != null) { 
     //check to make sure that we're not trying to re-initialize with the same datapool (by name) 
     //if we are, then leave 
     if(dp.getName().equals(this.getDatapool().getName())) return; 

     //this basically says "give me the iterator already associated to this pool" 
     IDatapoolIterator iterator = DatapoolFactory.get().open(dp, ""); 
     //if we have an iterator AND a data pool (from above), then we can initialize 
     if(iterator != null) { 
      //this method is never supposed to be run, but this works just fine. 
      this.dpInitialization(dp, iterator); 
      //log information 
      logInfo("Using data pool from root script: " + root.getScriptName()); 
     } 
    } 
} 
相關問題