网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
Postman沙箱集成了几个工具库,比如lodash、SugarJs、tv4,还有一些内置函数如xml2JSON…
tv4用于验证JSON数据,通过编写JSON Schema来验证,JSON Schema的语法请参照这里
测试语法:
// description 为该测试的描述 // value 只要Boolean(value)不等于false,这个测试就是PASS tests[description] = value // example tests["Status code is 200"] = responseCode.code === 200;
我们以github status的接口为例:
url: https://status.github.com/api/status.json
tests["Status code is 200"] = responseCode.code === 200; // validate json schema var schema = { properties: { status: {type:'string'}, last_updated: {type: 'string'} } }; tests["Valid data schema"] = tv4.validate(responseBody, schema); // check status var jsonData = JSON.parse(responseBody); tests["Github s