我需要一个测试用例来验证在没有必填字段的情况下进行 API 调用时是否返回了“400 Bad Request”。(以前有一个需要该字段的错误,但没有的请求被接受)
这是一个带有身份验证和原始正文的简单 POST 调用。返回缺少的字段时返回 200。
POST 正确返回“400 Bad Request”,但我无法通过测试。
以下测试均失败:
pm.test("Status is an error", function () {
pm.response.to.be.error;
});
pm.test("Status code is 400", function () {
pm.response.to.have.status(400);
});
响应正文是:
Instantiation of [simple type, class com.[company].[product].notifications.api.v2.models.NotificationCreateV2] value failed for JSON property content due to missing (therefore NULL) value for creator parameter content which is a non-nullable type
at [Source: (byte[])"{
"field1": "string",
"field2": "Snort",
"field3": "Signature 5102",
"field4": "2019-04-19T10:34:03Z",
"field5": 0,
"field6": 4
}"; line: 8, column: 1] (through reference chain: com.[company].[product].notifications.api.v2.models.NotificationCreateV2["content"])