How to test error codes with swagger and dredd?

最后都变了- 提交于 2020-01-25 03:55:42

问题


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?

Example:

Path /task/{id} can have 3 type of responses: 
200 -> OK
404 -> Task not found 
403 -> Forbidden(not your task)

Is it possible to test all 3 "workflows" for this path with swagger / dredd?


回答1:


It is possible with hooks. See the Choosing HTTP Transactions and Multiple Requests and Responses sections in Dredd's docs:

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();
});


来源:https://stackoverflow.com/questions/50051419/how-to-test-error-codes-with-swagger-and-dredd

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!