接口自动化测试框架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":"重定向成功"
    }
  }

]


 

你可能感兴趣的:(自动化技术栈)