存储和检索变量值

可使用 getValue() 和 setValue() 方法来存储和检索变量中的值。根据您指定的存储位置,变量可在测试之间进行共享,或本地存储在当前测试中。

可使用 getValue() 和 setValue() 方法来存储一个定制代码调用内的变量中的多个值。然后,可从变量而不是多个定制代码元素来创建替换。

例如,假定响应包含三个值:标识、书名和价格。您可以从响应中读取全部三个值,然后使用定制代码来设置变量 idtitleprice。您随后可以在测试中根据需要来对这三个变量中的值进行替换,而不必为每个变量都编写定制代码。

注: 传递到方法的存储位置必须与声明变量时使用的存储位置匹配。
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;
    }

反馈