POSTMAN返回失败以进行模式验证测试

编程入门 行业动态 更新时间:2024-10-24 04:35:20
本文介绍了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返回失败以进行模式验证测试

本文发布于:2023-10-29 08:16:13,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1539185.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:模式   测试   POSTMAN

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!