1
我用我的SOAP UI脚本看到了一些不寻常的东西。我只是想执行的断言,即用数据是正确的,所以我写了这个代码如下:如何通过groovy订购json输出?
import com.eviware.soapui.support.GroovyUtils
import groovy.json.JsonOutput
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def json = new JsonSlurper().parseText(response)
def jsonFormat = (response).toString()
def policies = [
[x: 28, xxx: 41, xxxxx: 1, name: 'Individual 18-50', aaa: true],
[x: 31, xxx: 41, xxxxx: 1, name: 'Individual 51-60', aaa: true],
[x: 34, xxx: 41, xxxxx: 1, name: 'Individual 61-75', aaa: true],
[x: 37, xxx: 41, xxxxx: 1, name: 'Individual 76-85', aaa: false]
]
log.warn json.policies
log.error policies
assert json.policies == policies
当我看log.warn和log.error信息,它会显示不正确的JSON响应因为它首先显示“isActive”字段。
log.warn json.policies
显示此:
[{aaa=true, xx=28, xxxxx=1, name=Individual 18-50, xxxx=41}, {aaa=true, x=31, xxxxx=1, name=Individual 51-60, xxx=41}, {aaa=true, x=34, xxxxx=1, name=Individual 61-75, xxx=41}, {aaa=true, x=37, xxxxx=1, name=Individual 76-85, xxx=41}]
log.error policies
显示此:
[{x=28, xxx=41, xxxxx=1, name=Individual 18-50, aaa=true}, {x=31, xxx=41, xxxxx=1, name=Individual 51-60, aaa=true}, {x=34, xxxx=41, xxxxxx=1, name=Individual 61-75, aaa=true}, {x=37, xxx=41, xxxxx=1, name=Individual 76-85, aaa=false}]
如何我必须按正确的顺序内的json.policies
显示的DTO,使其按照正确的顺序显示为政策?
另一个不寻常的事情是,我运行了10次测试用例,并且这个断言检查的测试步骤已经超过10次。它应该永远不会通过,就好像你比较最后的DTO作为policies
的结尾,它显示isActive
为假其中最后一个在json.policies
中的活动为为真。
Json地图没有订单 –
@ oh ok那么,我可以问一下,它有时会如何通过,并失败了断言?有没有我在代码中做了不正确的事情? –
因为有时它会以正确的顺序出现,而其他的不是。您不能依赖订单 –