自己写的话题详情接口测试,感觉比较傻,寻求更好的学习资料

官网测试用例的例子
Tiny Validator (for v4 JSON Schema)

自己参考了上面这两个,对话题详情接口做了一下sandbox测试。
先对collection写公共的pre-scritpt,设置一个环境变量备用。

pm.environment.set("schema_assertTrue", '{"items": {"type": "boolean"}}');

test-script如下:

pm.test("话题详情json结构", function () {
    pm.expect(pm.response.text()).to.include("id");
    pm.expect(pm.response.text()).to.include("title");
    pm.expect(pm.response.text()).to.include("body");
    pm.expect(pm.response.text()).to.include("user_id");
    pm.expect(pm.response.text()).to.include("category_id");
    pm.expect(pm.response.text()).to.include("reply_count");
    pm.expect(pm.response.text()).to.include("view_count");
    pm.expect(pm.response.text()).to.include("last_reply_user_id");
    pm.expect(pm.response.text()).to.include("excerpt");
    pm.expect(pm.response.text()).to.include("slug");
    pm.expect(pm.response.text()).to.include("created_at");
    pm.expect(pm.response.text()).to.include("updated_at");

    if(pm.expect(pm.response.text()).to.include("category")){
        if(pm.response.json().category instanceof Object){
            var data1 = [
                pm.response.json().category.hasOwnProperty('id'),
                pm.response.json().category.hasOwnProperty('description'),
                pm.response.json().category.hasOwnProperty('name'),
            ]
            pm.expect(tv4.validate(data1, pm.environment.get('schema_assertTrue'))).to.be.true;
        }
    }
});

pm.test("响应状态码", function () { 
    pm.response.to.have.status(200);
});

效果截图:
file
file

感觉这样写的比较傻,最终API黑盒测试就只能检查json格式的结构和返回的状态?

请问老师,不知道有没有更好的办法?
或者Tiny Validator (for v4 JSON Schema)这个有没有什么例子(上面那个github上的链接的例子已经找不到了)?
这里倒是找到一个文档,但是看着费劲。还不确定是不是它。。。

谢谢。

日拱一卒
《L05 电商实战》
从零开发一个电商项目,功能包括电商后台、商品 & SKU 管理、购物车、订单管理、支付宝支付、微信支付、订单退款流程、优惠券等
《L04 微信小程序从零到发布》
从小程序个人账户申请开始,带你一步步进行开发一个微信小程序,直到提交微信控制台上线发布。
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!