如何在 Rest Assured 中使用 then 方法?
我们可以在 Rest Assured 中使用 then 方法。它主要用于验证从请求中获得的响应。因此,大多数断言都包含在 then 方法中。
语法
RestAssured.baseURI = "http://dummy.restapiexample.com";
//GET operation with then methods
given()
.when().get("/api/v1/employees").then()
//verify status code as 404
.assertThat().statusCode(404);示例
代码实现
import org.testng.annotations.Test;
import static io.restassured.RestAssured.*;
import io.restassured.RestAssured;
public class NewTest {
@Test
void test() {
//base URL
RestAssured.baseURI =
"http://dummy.restapiexample.com";
//input details for GET request
given()
.when().get("/api/v1/employee/1")
//verify status code as 200 within then method
.then().log().all()
.assertThat().statusCode(200);
}
}输出

广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
JavaScript
PHP