码迷,mamicode.com
首页 > Web开发 > 详细

[SoapUI] Compare JSON Response(比较jsonobject)

时间:2017-08-07 16:41:22      阅读:257      评论:0      收藏:0      [点我收藏+]

标签:ase   代码   exce   log   and   bsp   lease   soap   tle   

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)

标签:ase   代码   exce   log   and   bsp   lease   soap   tle   

原文地址:http://www.cnblogs.com/MasterMonkInTemple/p/7299649.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!