本文介绍了POSTMAN返回失败以进行模式验证测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个样本回复:
{ "tags": [ { "id": 1, "name": "[String]", "user_id": 1, "created_at": "2016-12-20T15:50:37.000Z", "updated_at": "2016-12-20T15:50:37.000Z", "deleted_at": null } ] }我已经为响应写了一个测试:
I've written a test for the response:
var schema = { "type": "object", "properties": { "tags": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "user_id": { "type": "number" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" }, "deleted_at": { "type": ["string", "null"] } } } } }; var data = JSON.parse(responseBody); tests["Valid schema"] = tv4.validate(data, schema);此测试返回[FAIL].测试中有什么错误?
This test returns [FAIL]. What wrongs in the test?
感谢您的回复!
推荐答案tags的定义存在问题,因为它是数组而不是对象.您应该将其属性嵌套到其项属性中.
There is a problem on the definition of tags, since it's an array instead of an object. You should nest its properties into its items properties.
此代码通过了测试:
test_data = { "tags": [ { "id": 1, "name": "[String]", "user_id": 1, "created_at": "2016-12-20T15:50:37.000Z", "updated_at": "2016-12-20T15:50:37.000Z", "deleted_at": null } ] } test_schema = { "type": "object", "properties": { "tags": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer" }, "name": { "type": "string" }, "user_id": { "type": "number" }, "created_at": { "type": "string" }, "updated_at": { "type": "string" }, "deleted_at": { "type": ["string", "null"] } } } } } }; tests["Testing schema"] = tv4.validate(test_data, test_schema); console.log("Validation errors: ", tv4.error);更多推荐
POSTMAN返回失败以进行模式验证测试
发布评论