Karate 空手道比赛表情

Karate 空手道比赛表情,karate,Karate,我使用模式验证来验证响应,值返回一个数字或“NA”,下面是响应和模式验证 Response: { "ID": "ES123D74590Z", "companyName": "ABC Corp", "hourMs": 67890000000, "date": "2020-06-09T00:00:00.000Z", "scores": { "AllScore": 61, "MaxScore": 59, "Scor

我使用模式验证来验证响应,值返回一个数字或“NA”,下面是响应和模式验证

Response:
{
    "ID": "ES123D74590Z",
    "companyName": "ABC Corp",
    "hourMs": 67890000000,
    "date": "2020-06-09T00:00:00.000Z",
    "scores": {
        "AllScore": 61,
        "MaxScore": 59,
        "ScoreA": 75,
        "ScoreB": "NA",
        "ScoreC": 49,
        "ScoreD": "NA"
    },
    "movement": {},
    "amt": {}
}
Schema断言:
{
“ID”:“#字符串”,
“公司名称”:“#字符串”,
“小时数”:“#数字”,
“日期:“#regex[^\d\d\d\d-([0-9]{2})-([0-9]{2})(\T)([0-9]{3}):([0-9]{3}):([0-9]{3})\[0-9]{3}\Z$”,
“分数”:{

“AllScore”:“##number?>=0&&&&&u=0&&&u=0&&u=0&&u=0&&u=0&&u=0&&u0&&up>给你。试着在别人的帮助下检查你的代码。仔细阅读文档。下次,像这样简化你的问题

* def response =
"""
{
    "AllScore": 61,
    "MaxScore": 59,
    "ScoreA": 75,
    "ScoreB": "NA",
    "ScoreC": 49,
    "ScoreD": "NA"
}
"""
* def isNum = function(x){ if (x === 'NA') return true; return typeof x === 'number' }
* def schema =
"""
{
    "AllScore": '#? isNum(_)',
    "MaxScore": '#? isNum(_)',
    "ScoreA": '#? isNum(_)',
    "ScoreB": '#? isNum(_)',
    "ScoreC": '#? isNum(_)',
    "ScoreD": '#? isNum(_)'
}
"""
* match response == schema

另外,我建议您查看此日期验证示例以了解更多想法:

不完整的示例。请尝试改进您的问题。不需要剪切和粘贴。让其他人易于理解。请让我知道上述更新是否有用。感谢您的快速回复和解决方案。将对其进行审阅并简化问题nex时间到了。@VijayReddy,请看这个!
com.intuit.karate.exception.KarateException: score.feature:19 - path: $.scores.ScoreB, actual: 'NA', expected: '##number? _ >= 0 && _ <=100 || _ == "NA"', reason: not a number

* def response =
"""
{
    "AllScore": 61,
    "MaxScore": 59,
    "ScoreA": 75,
    "ScoreB": "NA",
    "ScoreC": 49,
    "ScoreD": "NA"
}
"""
* def isNum = function(x){ if (x === 'NA') return true; return typeof x === 'number' }
* def schema =
"""
{
    "AllScore": '#? isNum(_)',
    "MaxScore": '#? isNum(_)',
    "ScoreA": '#? isNum(_)',
    "ScoreB": '#? isNum(_)',
    "ScoreC": '#? isNum(_)',
    "ScoreD": '#? isNum(_)'
}
"""
* match response == schema