首页 > 代码库 > [SoapUI] Compare JSON Response(比较jsonobject)
[SoapUI] Compare JSON Response(比较jsonobject)
http://jsonassert.skyscreamer.org/
从这个网站下载jsonassert-1.5.0.jar ,也可以下载到源代码
JSONObject data = http://www.mamicode.com/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)
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。