Which method is used to validate the content of a JSON response in RestAssured?

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”.

Reference links:

https://www.javaguides.net/p/top-java-libraries.html

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top