【发布时间】:2014-08-31 22:03:46
【问题描述】:
我不熟悉 带有 SoapUI 的 Groovy 脚本。我必须将数组传递给方法并修改值,然后将它们打印在日志中。为此,我编写了以下脚本。但它没有按预期工作。
String [] countries = new String[5];
void ReuseArray(String[] regions){};
countries[0] = "India";
countries[1] = "Singapore";
countries[2] = "Indonesia";
countries[3] = "Japan";
countries[4] = "Thailand";
for (int i=0; i<5; i++)
{
log.info("Country :" + countries[i]);
}
ReuseArray(countries);
void ReuseArrayData(String[] regions)
{
for (int i=0; i<5; i++)
{
log.info("Method :" + regions[i]);
}
}
以上脚本产生以下输出:
IST 2014 年 7 月 10 日星期四 19:08:13:INFO:Welcome
2014 年 7 月 10 日星期四 19:08:13 IST:INFO:Country :India
2014 年 7 月 10 日星期四 19:08:13 IST:INFO:Country :Singapore
2014 年 7 月 10 日星期四 19:08:13 IST:INFO:Country :Indonesia
2014 年 7 月 10 日星期四 19:08:13 IST:INFO:Country :Japan
IST 2014 年 7 月 10 日星期四 19:08:13:INFO:Country :Thailand
如果我错了,请纠正我。
【问题讨论】:
-
脚本的输出是什么?
-
按照上面的脚本,它应该显示 5 个国家的名称列表,但它没有显示...
-
看来这和SoapUI无关,这只是Groovy的问题?此外,您的代码是纯 Java,甚至不是 Groovy ......这很好,因为 Groovy 与 Groovy 的源代码兼容 99%。您的脚本将不会产生
Welcome日志信息消息,但它会产生其他五个Country消息。您的方法ReuseArrayData()从未使用过。我看不出问题出在哪里。 -
那么我们不能在带有 SoapUI 的 Groovy 脚本中使用参数方法吗?
标签: testing groovy scripting automation soapui