准备数据
1 | # 三个list变量:list_a、list_b、list_c; |
断言实例
should contain
、should not contain
、should contain x times
1
2
3
4should contain ${list_b} 1.0
should not contain ${list_b} 1
should contain x times ${list_b} 21 2
# 变量${list_b}包含对象1.0而不包含对象1,且对象21在变量${lst_b}出现了两次should be empty
、should not be empty
1
2
3should be empty ${list_c}
should not be empty ${list_a}
# 变量${list_c}没有赋值,所以为空;相反,变量${list_a}有赋初始值,故为非空should be equal
、should not be equal
1
2
3should be equal ${list_a[1]} ${list_b[1]}
should not be equal ${list_a} ${list_b}
# ${list_a[1]}=a,${list_b[1]}=a故两个对象相等;而${list_a}和${list_b}有元素不一致,这两个对象不相等should be equal as numbers
、should not be equal as numbers
1
2
3should be equal as numbers ${list_b[0]} 1.0000
should not be equal as number ${list_b[0]} 1.1
# ${list_b[0]}=1,忽略精度,故与1.0000相等;而即使是忽略精度,1与1.1还是不相等的should be equal as integers
、should not be equal as integers
1
2
3
4should be equal as integers ${list_a[3]} ${list_b[3]}
should not be equal as integers ${list_a[4]} ${list_b[4]}
# ${list_a[3]}=21,${list_b[3]}=21,而系统默认为字符串格式的“21”,故需要转化为整数类型,转化为整数后两个对象相等
# ${list_a[4]}=12,${list_b[4]}=21,即使转化为整数后两个对象依旧是不相等should be equal as strings
、should not be equal as strings
1
2
3should be equal as strings ${list_a[2]} ${list_b[2]}
should not be equal as strings ${list_a[0]} ${list_b[0]}
# ${list_a[2]}=${21},${list_b[2]}=${21},而均为数值型的21,故需要转化为字符串类型,转化为字符串后两个对象相等should be true
、should not be true
1
2
3should be true ${list_a[0]} < 10
should not be true ${list_a[0]} < 1
# ${list_a[0]}=1(字符串类型),其ASCII值比字符串10的ASCII值小should start with
、should not start with
1
2
3should start with ${string} tao
should not start with ${string} h
# ${string}="taoyi is in hangzhou"是以sha开头,而非以h开头should end with
、should not end with
1
2
3should end with ${string} hangzhou
should not end with ${string} taoyi
# ${string}="taoyi is in hangzhou"是以hangzhou结尾,而非以taoyi结尾should match
、should not match
1
2
3
4should match ${name} t?
should not match ${string} h?*
# 模式匹配和shell中的通配符类似,它区分大小写,'*'匹配0~无穷多个字符,“?”单个字符
# ${name}=ty,由以t开头的两个字母组成should match regexp
、should not match regexp
1
2
3
4should match regexp ${name} ^\\w{2}$
should not match regexp ${name} ^\\d{2}$
# 反斜杠在测试数据是转义字符,因此模式中要使用双重转义;'^'和'$'字符可以用来表示字符串的开头和结尾
# ${name}=ty,是有两个字母--w{2}组成,而不是由两个数字--d{2}组成