其他分享
首页 > 其他分享> > Mock基础知识

Mock基础知识

作者:互联网

使用的框架:moco框架
下载地址:https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/1.1.0/

启动方式:
java -jar ./moco-runner-1.1.0-standalone.jar http -p 8899 -c json文件
注意:mocorunner是热部署,服务不用重启,即可完成升级操作


mock接口
字段值
字段含义
子字段值
子字段含义


description
描述

 

request
请求代码块
uri
请求地址

 


method
请求方法

 


queries
get方法请求参数时用

 


forms
post方法请求参数时用

 


redirectTo
重定向到哪一个uri中

 


cookies

cookies信息
key
cookie名称


value
cookie值


headers
请求头


response
返回代码块

 

 

Get请求
[
{
"description": "无参get请求",
"request":{
"uri": "/getNoParams",
"method": "get"
},
"response":{
"text": "无参数get请求成功"
}
},

{
"description": "有参get请求",
"request":{
"uri": "/getWithParams",
"method": "get",
"queries": {
"name": "zhangsan",
"age": "18"
}
},
"response":{
"text": "有参数get请求成功"
}
},

{
"description": "有参get请求返回json",
"request":{
"uri": "/getWithParams2",
"method": "get",
"queries": {
"name": "lisi",
"age": "17"
}
},
"response":{
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
},

{
"description": "有参get请求json",
"request":{
"uri": "/getWithParams3",
"method": "get",
"json": {
"name": "wangwu",
"age": 16
}
},
"response":{
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
}
]
Post请求
[
{
"description": "无参数post请求",
"request": {
"uri": "/postNoparams",
"method": "post"

},
"response": {
"text": "无参post请求"
}
},

{
"description": "有参数post请求",
"request": {
"uri": "/postWithparams",
"method": "post",
"forms": {
"name": "zhangsan",
"age": "18"
}
},
"response": {
"text": "有参数post请求"
}
},
{
"description": "有参数post请求",
"request": {
"uri": "/postWithparams2",
"method": "post",
"json": {
"name": "zhangsan",
"age": 18
}
},
"response": {
"status": "200",
"json":{
"msg": "success",
"status": "10000"
}
}
},

{
"description": "携带cookies的请求",
"request": {
"uri": "/postwithCookies",
"method": "post",
"forms": {
"name": "lisi",
"age": "17"
},
"cookies": {
"session": "true"
}
},
"response": {
"text": "携带cookies的请求"
}
},

{
"description": "携带header的请求",
"request": {
"uri": "/postwithHeader",
"method": "post",
"forms": {
"name": "lisi",
"age": "17"
},
"headers": {
"session": "true",
"Content-Type":"application/json"
}
},
"response": {
"text": "携带header的请求"
}
}
]

标签:请求,get,uri,基础知识,post,method,Mock,description
来源: https://www.cnblogs.com/wanggfIT/p/16519957.html