测试基础-10-Moco使用

本文详细介绍了Moco框架中关于request和response的使用,包括description、request-uri、request-queries、request-method、request-headers、request-cookies等字段的配置,以及response-text、response-file、response-status、response-proxy等响应设置。同时,讲解了Redirect重定向功能,帮助理解Moco在测试中的应用。
摘要由CSDN通过智能技术生成

前言

上一篇搭建好了moco环境,本篇为moco中request和response的具体使用

 

moco使用(request部分)

1)description字段,在所有JSONAPI中,可以使用description来描述这个会话的目的。它只是用作注释,在运行时将被忽略。

//test.json
[
   {
        "description": "any response",
        "response": {
            "text": "foo"
        }
    }
]

2)request字段,根据请求进行响应

//test.json
[
   {
      "request" :
      {
         "text" : "foo"
      },
      "response" :
      {
         "text" : "bar"
      }
   }
]

3)request-uri字段,根据不同url响应不同信息

//test.json
[
   {
      "request" :
      {
         "uri" : "/foo"
      },
      "response" :
      {
         "text" : "bar"
      }
   }
]

浏览器输入:localhost:12306/foo,会返回“bar”

 

4)request-queries字段,请求带参数

//test.json
[
   {
      "request" :
      {
         "uri" : "/foo",
          "queries" : 
         {
            "param" : "blah"
         }
       },
      "response" :
       {
          "text" : "bar"
      }
   }
]

浏览器输入:localhost:12306/foo?param=blah,会返回“bar”

 

5)request-method字段,请求方法(以get为例,其他方法与其操作一致)

//test.json
[
   {
      "request" :
      {
         "method": "get",
         "uri" : "/foo"
       },
      "response" :
       {
          "text" : "bar"
      }
   }
]

6)request-headers字段,设置请求头信息

//
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值