首页 > 其他 > 详细

Groovy读取properties

时间:2015-10-01 10:15:56      阅读:1298      评论:0      收藏:0      [点我收藏+]

昨晚帮老同事解决了一个SoapUI的代码问题,好长时间没用SoapUI,好多东西都忘了,今天先总结下Groovy读取properties

首先吐槽下SoapUI的apidocs,我几乎从中看不出什么东西,官网的tips有那么一点用,但是好长时间没有更新了,好多东西都找不到。而且在SoapUI里调试Groovy代码几乎不太可能。

APIDocs: http://www.soapui.org/apidocs/index.html?com/eviware/soapui/model/testsuite/TestRunContext.html

废话不多说,首先获取当前的testsuite:

def ts =  testRunner.testCase.testSuite

获取的properties文件路径:

def filename =  “C:\\TestSuiteProperties\\CurrentTestingEnvironment\\endpoints.properties"
log.info "Loading properties from " + filename

使用java包导入properties:

def props = new java.util.Properties();
props.load( new java.io.FileInputStream(filename));

利用Emumeration读取properties value,并设置到testsuite的properties中去:

Enumeration e = props.keys();
while (e.hasMoreElements())
{
    key = e.nextElement();
    val = props.get(key);
    ts.setPropertyValue(key, val);
    log.info "Set property " + key + " to " + val;
}

这是一个properties参数的初始化过程。

Groovy读取properties

原文:http://www.cnblogs.com/goldenRazor/p/4850670.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!