我对服务测试和 Groovy 很陌生。以下是我的回复,
{
encodedDiscountId=1275479,
encodedGuid=gOHSkGzQEee4-AJiXJP2jg,
expirationDate=2017-08-17 17:00:00
}
我需要以下断言的帮助:
- 我需要断言 DiscountId 值是否都是 7 位长的随机数字。
- 我需要用“-”断言我得到一个大写和小写的字母数字
- 我需要断言 expireDate 应该是系统日期后的 30 天。
我尝试了脚本断言并不断收到此错误。
import groovy.json.JsonSlurper
def response = messageExchange.response.responseContent
def slurper = new JsonSlurper()
def json = slurper.parseText(response)
assert json.encodedDiscountId.size() == 7
assert json.encodedDiscountId.matches("[0-9]")
错误:
assert json.encodedDiscountId.matches("[0-9]") | | | | 1043947 false [encodedDiscountId:1043947, encodedGuid:l0wWcG2KEee4-AJiXJP2jg, expirationDate:2017-08-18 17:00:00]