持续三篇,每周一篇拖延症终究还是犯了。但是毕竟说过的话,如同泼出去的水,还是得兑现。不管阅读量,不管评论,不管成效。这次,我们将讲解下SoapUI的TestCase 断言。
SoapUI系列教程请点击下列链接:
1、SoapUI 入门之创建Project、生成TestCase以及参数化
2、SoapUI 入门之配置Headers,以及将Cookie、Token持久化存储
TestCase断言
一、SoapUI断言的分类
断言有几个大的分类:
(1) Property Content 该类断言可以让你用XPath、XQuery、JsonPath等表达式验证request和response的内容
(2) Compliance Assertions 该类断言将处理验证service定义和message消息结构(xml、json等)
(3) Script 该断言将运行你的Groovy脚步,并验证信息。可以验证消息内容、header、property属性等内容
(4) Response SLA 该断言将判断响应是否在指定的时间内返回
(5) JDBC Assertions 该类断言将验证JDBC 数据库连接状态和是否超时等
(6) JMS Assertions 该类断言将验证JMS(Java消息服务)的状态和是否超时
(7) Security Assertions 该类断言将验证你收到的response是否包含不安全的内容
以上7个大类是SoapUI断言的分类,在1、2、5、6、7类下又有其他详细的子类分类,而我们用的比较多的断言是Property Content、Compliance、Script、Response SLA大类,下边我们将对这几大类下的常用的具体断言列举一下。
1、Property Content
在这个Property Content断言大类中,也可以分成几小类:Content(内容)、JSONPath(JSONPath表达式)、XPath(Xpath表达式)、XQuery(XQuery表达式)
(1) Content:
Contains Assertion:此断言将在Request和response中搜索是否包含指定的内容
No Contains Assertion:此断言将判断request和response中是否不包含指定内容
Equals Assertion: 此断言将检查属性值是否和response内容相等
Message Content Assertion:此断言将检查response消息内容,字段预期值和实际值之间的比较(可以设置大于/等于/小于等运算符)
(2) JSONPath
JSONPath Count Assertion:此断言将使用JSONPath表达式选择指定字段,并判断在request或response出现次数是否和预期次数相等
JSONPath Existence Match Assertion:此断言使用JSONPath表达式选择指定字段,并判断是否在response返回消息中存在
JSONPath RegEx Match Assertion:此断言使用JSONPath表达式从response返回消息中选择你想要的字段,并同你所填入的正则表达式匹配,看是否能匹配上
JSONPath Match Assertion:此断言使用JSONPath表达式选择你需要的字段,并比较判断该字段的实际值和指定值是否相等
(3) XPath
XPath Match Assertion:此断言使用Xpath表达式从request或response中选择你所需的字段,并比较判断该node的实际值和预期值是否相等
2、 Compliance
HTTP Download Resources:此断言检查链接下载资源是否是有用的、可下载的
HTTP Valid Status Codes:此断言检查Http请求返回的状态码是否在定义的状态码列表中
HTTP Invalid Status Codes:这个断言与上一个是相反的,检查状态码是否不在定义的列表中
Header Equals Assertion:此断言检查你指定的header字段是否存在,并且值是否和你的预期值一致
Header Exists Assertion:顾名思义,此断言检查指定的Header是否存在于Request或response中
二、如何为TestStep添加断言
在TestCase界面中,我们点击下方Assertion按钮或者点击图2.1中绿色+号,打开断言对话框


三、常用的断言的使用
1、Property Content
(1)Contains Assertion(No Contains Assertion类似,不再截图了)

(2) Equals Assertion
这个断言有两种Mode:Text和Other Property
Text Mode:

Other Property Mode:

(3) Message Content Assertion

(4)JSONPath Count Assertion

(5)JSONPath Existence Match Assertion

(6)JSONPath Match Assertion

(7)JSONPath RegEx Match Assertion

(8)XPath Match Assertion

2、Compliance
(1)HTTP Valid Status Codes

(2)HTTP Invalid Status Codes

(3)Header Equals Assertion

(4)Header Exists Assertion

3、Response SLA

4、Script
ScoapUI中一般使用Groovy语言作为脚本语言,现在也可以用javaScript,但是要引入库,这里暂时以Groovy为主

好了,到这ScoapUI TestCase断言部分基本上讲完了,本来是计划把上传附件和Https请求一起讲的,但是一写觉得断言单独一节比较好,因为很多文章讲到断言基本是翻译了一下文档,我这里图文并茂了下,希望您看完后,真正学会了用一些断言,这才是我真实的目的,那下一节接着没讲完的附件上传和Https请求吧。Thanks♪(・ω・)ノ
申明:禁用于商业用途,如若转载,请附带原文链接。https://www.jianshu.com/p/ee0da5abf49d 蟹蟹(#^.^#)
网友评论