码迷,mamicode.com
首页 > 其他好文 > 详细

soapUI 学习总结

时间:2017-06-13 11:24:11      阅读:196      评论:0      收藏:0      [点我收藏+]

标签:name   rac   准备   content   blog   script   sse   需要   ati   

 

 

一 断言

测试指定的restful api是否正常,判断它的响应值是否符合预期标准,需要用到断言知识。

1,准备测试数据

以下是准备的测试数据,它是一个JSON格式的数据列表。在resources节点中,它包含3个用户消息子节点。

{
   "total": 3,
   "resources":    [
            {
         "username": "test03-SD",
         "created": "1496800026000",
         "uuid": "8f6cae8a24ab4d0887dd5907430075e7",
         "contractNumber": "131"
      },
            {
         "username": "test02",
         "created": "1489479452000",
         "name": "8bbf9fded675472aa852cf1940bc8234",
         "contractNumber": "133"
      },
            {
         "username": "test01",
         "created": "1487576620000",
         "name": "156b396f9b354467b5d1d1a1014b2d10"
      }
   ],
   "time": "2017年06月13日 10时25分07秒",
   "pageNum": 1
}

 

使用Script Assertion 测试JSON 格式的列表,在Script Assertion 窗口中写入如下代码:

def booksRoot = net.sf.json.JSONSerializer.toJSON(messageExchange.responseContent);  
def total = booksRoot.get("total"); 

assert total == 3

返回结果如下:

技术分享

可以看到断言中total对应的值与测试值是一样的,如果故意写错,会怎么样呢?错误的断言如下:

def booksRoot = net.sf.json.JSONSerializer.toJSON(messageExchange.responseContent);  
def total = booksRoot.get("total"); 

assert total == 10

返回结果如下:

技术分享

可以看到soapUI提示断言中total的判断是错误的,应该为3。

 

 

 

 

参考资料:

https://www.soapui.org/functional-testing/validating-messages/using-script-assertions.html

https://wenku.baidu.com/view/40b3598e680203d8ce2f245e.html

 

soapUI 学习总结

标签:name   rac   准备   content   blog   script   sse   需要   ati   

原文地址:http://www.cnblogs.com/wangshuo1/p/6999796.html

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