接下去我们会开始了解Rest-assured
1. Rest-assured的优势2. Rest- assured的环境准备简约的接口测试DSL.
支持XML/JSON的结构化解析
支持XPath/ jsonpath / gpath解析方式
对spring的支持比较全面
符合契约编程思想
新建maven项目,pom添加依赖。 这里我们使用rest-assured和junit5集成。
io.rest-assured rest-assured4.4.0
junit5依赖
3. Rest-assured语法规则org.junit.platform junit-platform-launcher1.5.2 org.junit.jupiter junit-jupiter-engine5.5.2 org.junit.vintage junit-vintage-engine5.5.2
Rest-assured语法规则是,Given(测试准备),When(测试执行), Then(测试验收)
3. 第一个get接口请求1. 新建一个测试类
2. 新建一个测试方法
3. 发起一个Rest-assured接口请求
import static io.restassured.RestAssured.given;
import org.junit.jupiter.api.Test;
public class TestRestAssured {
@Test
void fun() {
given()
.when().get("https://httpbin.ceshiren.com/get")
.then()
.log().all();
}
}
结果
HTTP/1.1 200 OK
Date: Thu, 26 May 2022 13:41:52 GMT
Content-Type: application/json
Content-Length: 406
Connection: keep-alive
Access-Control-Allow-Origin: *
Access-Control-Allow-Credentials: true
Strict-Transport-Security: max-age=15724800; includeSubDomains
{
"args": {
},
"headers": {
"Accept": "*/*",
"Accept-Encoding": "gzip,deflate",
"Hello": "pig",
"Host": "httpbin.ceshiren.com",
"User-Agent": "Apache-HttpClient/4.5.13 (Java/1.8.0_202)",
"X-Forwarded-Host": "httpbin.ceshiren.com",
"X-Forwarded-Scheme": "https",
"X-Scheme": "https"
},
"origin": "10.7.136.128",
"url": "https://httpbin.ceshiren.com/get"
}



