霍格沃兹测试开发
ceshiren.com
JSON Schema 在线生成工具:https://app.quicktype.io
# 预期的 JSON 文档结构
{
"name": "Hogwarts",
"rank": 1,
"Courses": [
"UI Auto Testing",
"Java",
"Docker",
"JUnit5"
]
}
import org.junit.jupiter.api.Test;
import static io.restassured.RestAssured.given;
import static io.restassured.module.jsv.JsonSchemaValidator.matchesJsonSchemaInClasspath;
public class TestJsonSchema {
@Test
void func() {
given()
.header("Hello", "Hogwarts")
.when()
.get("https://httpbin.ceshiren.com/get") // 发送请求
.then()
.log().all() // 打印完整的响应信息
.assertThat()
.body(matchesJsonSchemaInClasspath("schema.json")); // JSON Schema 断言
}
}
pom.xml
中添加配置信息