抛出"java.lang. net "错误。不能调用方法readLine()上的空对象错误在第1行,当下面的groovy脚本运行SOAP UI版本5.1.3
nextLine = context.fileReader.readLine()
if(nextLine != null){
String[] propData = nextLine.split(",")
curTC = testRunner.testCase
错误信息很清楚,context.fileReader
是空的,因为context
内部没有属性fileReader
,这就是为什么当你调用readLine()
时你得到NPE
。
要使用context.fileReader
,首先你必须在属性中设置一些东西,例如在你的例子中:
context.fileReader = new FileReader("/myTempFile.txt")
def nextLine = context.fileReader.readLine()
if(nextLine != null){
String[] propData = nextLine.split(",")
curTC = testRunner.testCase
这个例子毫无意义,它只是说明;通常,SOAPUI中的context
用于在TestCase执行中将不同的对象从一个testStep传递到另一个testStep,或者在TestSuite中从一个TestCase传递到另一个TestCase……
context.fileReader = new FileReader("/myTempFile.txt")
然后在另一个TestStep中你把它取回来作为:
def nextLine = context.fileReader.readLine()
希望有帮助,