如何用大张旗鼓和dredd测试错误代码? [英] How to test error codes with swagger and dredd?
问题描述
有想法如何使用Dredd结合swagger .yaml文件测试其余api错误代码吗?
Any Idea how the rest api error codes can be tested with Dredd in combination with swagger .yaml file?
是否有最佳实践,如何测试路径的所有不同错误?
Is there a best practice how to test all the different errors for the paths?
示例:
Path /task/{id} can have 3 type of responses:
200 -> OK
404 -> Task not found
403 -> Forbidden(not your task)
是否可以用招摇/dredd测试该路径的所有3个工作流"?
Is it possible to test all 3 "workflows" for this path with swagger / dredd?
推荐答案
It is possible with hooks. See the Choosing HTTP Transactions and Multiple Requests and Responses sections in Dredd's docs:
使用OpenAPI 2格式时,默认情况下,Dredd仅测试状态码为
2xx
的响应.带有其他代码的响应被标记为已跳过,可以在挂钩中激活:
When using OpenAPI 2 format, by default Dredd tests only responses with
2xx
status codes. Responses with other codes are marked as skipped and can be activated in hooks:
var hooks = require('hooks');
hooks.before('/resource > GET > 500 > application/json', function (transaction, done) {
transaction.skip = false;
done();
});
这篇关于如何用大张旗鼓和dredd测试错误代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!