一.moco框架mock接口信息
[
{
"description": "这是一个能返回cookies信息的get请求",
"request": {
"uri": "/getCookies",
"method": "get"
},
"response": {
"cookies": {
"login": "true"
},
"text": "成功获取到cookies信息啦"
}
},
{
"description": "这是一个携带cookie和param的get请求",
"request": {
"uri": "/get/with/cookieparam",
"method": "get",
"cookies": {
"login": "true"
},
"queries": {
"name": "lucy",
"age": "17"
}
},
"response": {
"status": 200,
"json": {
"cookie": "success",
"lucy": "success"
}
}
}
]
二.application.properties配置文件信息
test.url=http://localhost:8080
getCookies.uri=/getCookies
test.get.with.cookies=/get/with/cookie
test.get.with.cookiesAndParams=/get/with/cookieparam
三.编写testNG测试方法
package com.course.httpclient.cookies;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.client.CookieStore;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.