idea使用RestAPITester进行测试
2018-06-29 本文已影响32人
小谷先生
背景
- 在编写程序的时候通常需要写接口测试。一般老办法是通过安装PostMan进行调试测试,现在Idea编辑器有一种自动安装好的组件叫做RESTful WebServices,能达到的效果就是做接口测试。只需要在项目中新建一个文件叫做x.rest或者x.http即可。
测试方法
- Get请求
GET https://httpbin.org/ip
Accept: application/json
- auth请求
### Authorization by token, part 1. Retrieve and save token.
POST https://httpbin.org/post
Content-Type: application/json
{
"token": "my-secret-token"
}
> {% client.global.set("auth_token", response.body.json.token); %}
- POST请求
### Send POST request with json body
POST https://httpbin.org/post
Content-Type: application/json
{
"id": 999,
"value": "content"
}
### Send POST request with body as parameters
POST https://httpbin.org/post
Content-Type: application/x-www-form-urlencoded
id=999&value=content
### Send a form with the text and file fields
POST https://httpbin.org/post
Content-Type: multipart/form-data; boundary=WebAppBoundary
--WebAppBoundary
Content-Disposition: form-data; name="element-name"
Content-Type: text/plain
Name
--WebAppBoundary
Content-Disposition: form-data; name="data"; filename="data.json"
Content-Type: application/json
< ./request-form-data.json
--WebAppBoundary--