空手道Scenerio创建以测试以JSON格式返回的错误消息

时间:2018-12-12 05:09:31

标签: karate

我有一个get操作,在获取无效数据时会返回以下格式

{
    "exchangeReturnCod": "ERROR",
    "errors": [
        {
            "code": "XXX",
            "severity": "ERROR",
            "source": "Application with id APPLICATIONNOTEXIST doesn't exist.",
        }
    ]
}

我要在功能文件中匹配此错误消息。我使用了以下语法,但是没有用。

并匹配response.feedbacks错误 {来源:“ ID为APPLICATIONNOTEXIST的应用程序不存在。”}

您能指导我在这里做错什么吗?

1 个答案:

答案 0 :(得分:1)

这应该有效,

* def expected = {source:"Application with id APPLICATIONNOTEXIST doesn't exist."}
* match $response.errors[*].source contains expected.source

由于您的响应返回了一个errors数组,这将验证至少一个错误应该具有预期的来源。