[SoapUI] Compare JSON Response(比较jsonobject)

Posted 张缤分

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了[SoapUI] Compare JSON Response(比较jsonobject)相关的知识,希望对你有一定的参考价值。

http://jsonassert.skyscreamer.org/

从这个网站下载jsonassert-1.5.0.jar ,也可以下载到源代码

JSONObject data = getRESTData("/friends/367.json");
String expected = "{friends:[{id:123,name:\"Corby Page\"},{id:456,name:\"Carter Page\"}]}";
JSONAssert.assertEquals(expected, data, false);

SoapUI里面没有这个jar,把它放在lib目录下,在SoapUI里面调用如下:

import org.skyscreamer.jsonassert.*
import org.json.JSONObject

def currentStepIndex = context.currentStepIndex
def previousStepName = testRunner.testCase.getTestStepAt(currentStepIndex-1).name
def prePreStepName = testRunner.testCase.getTestStepAt(currentStepIndex-2).name
try{
	def expectedJson = new JSONObject(context.expand( ‘${‘+prePreStepName+‘#Response}‘ ))
	def actualJson = new JSONObject(context.expand( ‘${‘+previousStepName+‘#Response}‘ ))
	
	//When strict is set to false (recommended), it forgives reordering data and extending results (as long as all the expected elements are there), making tests less brittle.
	JSONAssert.assertEquals(expectedJson, actualJson, false)
}catch(Exception e){
	log.info e
}

  

以上是关于[SoapUI] Compare JSON Response(比较jsonobject)的主要内容,如果未能解决你的问题,请参考以下文章

soapUI 怎么发送json 报文请求?

使用soapui验证JSON

[SoapUI] 比较JSON Response

SoapUI对于Json数据进行属性值获取与传递

soapui 发送post请求,接收方式json 输入代码如下

[JSON123] A JSON Compare Tool