<dependency> <groupId>io.rest-assured</groupId> <artifactId>rest-assured</artifactId> <version>4.3.0</version> <scope>test</scope> </dependency> import static io.restassured.RestAssured.*; Response response = get("https://api.example.com/users/1"); int statusCode = response.statusCode(); import static io.restassured.RestAssured.*; import io.restassured.http.ContentType; String requestBody = "{\"username\": \"testuser\", \"password\": \"testpass\"}"; given() .contentType(ContentType.JSON) .body(requestBody) .when() .post("https://api.example.com/users") .then() .statusCode(201); import static io.restassured.RestAssured.*; given() .pathParam("userId", 1) .when() .get("https://api.example.com/users/{userId}") .then() .statusCode(200) .body("name", equalTo("John Doe")) .body("age", greaterThan(18)); import static io.restassured.RestAssured.*; import io.restassured.authentication.*; given() .auth().basic("username", "password") .when() .get("https://api.example.com/secure") .then() .statusCode(200); import static io.restassured.RestAssured.*; RestAssured.proxy("localhost", 8888); given() .when() .get("https://api.example.com") .then() .statusCode(200); import static io.restassured.RestAssured.*; given() .header("Content-Type", "application/json") .cookie("SESSION_ID", "abc123") .when() .get("https://api.example.com") .then() .statusCode(200); import static io.restassured.RestAssured.*; import static org.hamcrest.Matchers.*; given() .when() .get("https://api.example.com") .then() .statusCode(200) .body("users", hasSize(3)) .body("users[0].name", containsString("John"));


上一篇:
下一篇:
切换中文