接口自动化测试框架HttpClient-3-mock接口

1.1mock讲解

  mock是一个·超简单的接口测试工具 支持get方法,post方法,header,cookie,重定向  不仅给测试人员使用,还可以给前端开发人员使用

mock框架为github开源项目https://github.com/dreamhead/moco/tree/master/moco-runner

  或jar包下载地址 https://repo1.maven.org/maven2/com/github/dreamhead/moco-runner/0.11.0/moco-runner-0.11.0-standalone.jar

1.2mock使用

启动方式:java -jar ./moco-runner-0.11.0-standalone.jar http -p 8888 -c config.json

 -p后跟端口号,-c后跟json配置文件(json配置文件 可以是绝对路径也可以是相对路径,都是针对执行该命令行的路径来说的 )

 

get请求无参数:

[
	{		
		"description":"这是Mock接口的Demo",
		"request":{			
			"uri":"/GetDemo",
			"method":"get"			
		},
		
		"response":{
			"text":"This is Get request"		
		}	
	}
]

get请求带参数:

[
	{		
		"description":"这是Mock接口的Demo",
		"request":{			
			"uri":"/GetDemo",
			"method":"get",
			"queries":{
				"name":"Anndy",
				"age":"18"
			}
		},
		
		"response":{
			"text":"This is Get request name=Anndy"		
		}	
	}
]

post请求不带参数:

[
	{		
		"description":"这是Mock接口的Demo",
		"request":{			
			"uri":"/PostDemo",
			"method":"Post"
		},
		
		"response":{
			"text":"This is Post request"		
		}	
	}

]

post请求带参数 

[
	{		
		"description":"这是Mock接口的Demo",
		"request":{			
			"uri":"/PostDemo",
			"method":"Post",
			"forms":{
				"name":"Anndy",
				"age":"18"
			}
		},
		
		"response":{
			"text":"This is Post request"		
		}	
	}
]

请求重定向:

[
  {
    "description": "重定向到百度",
    "request": {
      "uri": "/redirect"
    },
    "redirectTo":"http://www.baidu.com"
  },
  {
    "description": "这是被重定向到的请求",
    "request": {
      "uri": "/redirect/new"
    },
    "response":{
      "text":"重定向成功"
    }
  }

]


 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

程序员路同学

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值