儲存及擷取變數值

您可以使用 getValue() 及 setValue() 方法來儲存及擷取變數中的值。 視您指定的儲存體位置而定,變數可在測試之間共用,或是儲存在現行測試的本端。

您可以使用 getValue() 及 setValue() 方法,將變數中的多個值儲存在一個自訂程式碼呼叫中。 然後,您可以從變數中建立替代,而不用從多個自訂程式碼元素中建立。

例如,假設回應包含三個值:id、book title 及 price。您可以從回應中讀取所有這三個值,然後使用自訂程式碼來設定 idbook titleprice 變數。然後,如有必要,您可以在測試中,以這三個變數來替代值,而不必為每個變數撰寫自訂程式碼。

註: 傳遞至該方法的儲存體位置必須符合宣告該變數時所使用的儲存體位置。
package customcode;

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

/**
     * For Javadoc information on the ICustomCode2 and ITestExecutionServices interfaces,
     * see the 'Extending test execution with custom code' help topic.
     */

/**
 * @author IBM Custom Code Samples
 */

    public String exec(ITestExecutionServices tes, String[] args) {
        
        tes.getValue("myVar", tes.STORAGE_USER);  // This retrieves a value from a test for the variable called myVar. The storage area is shared between tests.
        tes.getValue("myLocalVar", tes.STORAGE_LOCAL);  // This variable is stored locally, per test.
        
        tes.setValue("myVar", tes.STORAGE_USER, "myNewValue");  // Change the value of the variable myVar, which is shared between tests, to myNewValue.
        tes.setValue("myLocalVar", tes.STORAGE_LOCAL, "myLocalNewVar");  // Change the value of the local variable to myLocalNewVar.
        			return null;
    }

意見