霍格沃兹测试开发学社
ceshiren.com
given():可以设置测试预设
param():URL 查询参数when():所要执行的操作
get():GET 请求post():POST 请求then():可以解析结果、断言
statusCode():响应状态码断言import static io.restassured.RestAssured.given;
import org.junit.jupiter.api.Test;
public class TestRestAssuredGet {
@Test
void testGet(){
given()
// 可以设置测试预设
.param("username", "Hogwarts") // 设置查询参数
.when()
// 发起 GET 请求
.get("https://httpbin.ceshiren.com/get")
.then()
// 解析结果
.log().all() // 打印完整响应信息
.statusCode(200); // 响应断言
}
}import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
public class TestRestAssuredPost {
@Test
void testPost(){
given()
// 可以设置测试预设
.param("username", "Hogwarts") // 设置查询参数
.when()
// 发起 POST 请求
.post("https://httpbin.ceshiren.com/post")
.then()
// 解析结果
.log().all() // 打印完整响应信息
.statusCode(200); // 响应断言
}
}?username=Hogwarts&id=666param():查询参数queryParam():查询参数formParam():表单参数import static io.restassured.RestAssured.given;
import org.junit.jupiter.api.Test;
public class TestRestAssuredGet {
@Test
void testGet(){
given()
// 可以设置测试预设
.param("username", "Hogwarts") // 设置查询参数
.when()
// 发起 GET 请求
.get("https://httpbin.ceshiren.com/get")
.then()
// 解析结果
.log().all() // 打印完整响应信息
.statusCode(200); // 响应断言
}
}