Which method is used to validate the content of a JSON response in RestAssured?
A) body()
B) content()
C) jsonPath()
D) assertThat()
Answer:
A) body()
Explanation:
The body()
method in RestAssured is used to validate the content of a JSON response. It allows you to assert that specific fields in the JSON response contain the expected values.
For example:
import static io.restassured.RestAssured.*;
given().
when().
get("/api/resource").
then().
statusCode(200).
body("key", equalTo("value"));
In this example, the body()
method asserts that the “key” field in the JSON response has the value “value”.