本文介绍了如何用大张旗鼓和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?

推荐答案

可以使用挂钩.请参见选择HTTP交易多个请求和响应部分:

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

var hooks = require('hooks');

hooks.before('/resource > GET > 500 > application/json', function (transaction, done) {
  transaction.skip = false;
  done();
});

这篇关于如何用大张旗鼓和dredd测试错误代码?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-21 04:13