问题
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