Essential Rest Assured Interview Questions and Answers

5/5 - (1 vote)

Rest Assured Interview Questions and Answers are the most commonly asked interview questions we have listed with answers. we will see What is rest assured, it’s features, response body validation, methods, how to handle cookies etc.

We have covered a few postman interview questions as well in our previous posts. If you are fresher and wants to prepare for API Testing then this post is for you.

What is Rest Assured?

Rest Assured is an open-source Java library that is used for testing RESTful APIs. It provides a simple and intuitive way to interact with HTTP endpoints and validate the responses.

Explain the main features of Rest Assured.

  • Simplified syntax for making HTTP requests.
  • Support for various authentication mechanisms.
  • Ability to send various types of request payloads (JSON, XML, etc.).
  • Easy validation of response data using a fluent interface.
  • Support for extracting data from responses.

How can you add Rest Assured to a Maven project?

You can add Rest Assured to a Maven project by adding the following dependency to your pom.xml file:

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
</dependency>

What is a Request Specification in Rest Assured?

A Request Specification is a configuration object in Rest Assured that allows you to define common properties (e.g., base URI, port, authentication) for all HTTP requests.

Explain how to send a GET request using Rest Assured.

Response response =
given()
.when()
.get(“/endpoint”);

How do you validate the status code of a response in Rest Assured?

Response response =
given()
.when()
.get(“/endpoint”);

int statusCode = response.getStatusCode();

What is a Response Specification in Rest Assured?

A Response Specification is a configuration object in Rest Assured that allows you to define common properties (e.g., expected status codes, headers) for all HTTP responses.

How do you validate the response body in Rest Assured?

given()
.when()
.get(“/endpoint”)
.then()
.assertThat()
.body(“key”, equalTo(“value”));

Explain how to send a POST request with a JSON payload in Rest Assured.

given()
.contentType(ContentType.JSON)
.body(“{\”key\”: \”value\”}”)
.when()
.post(“/endpoint”);

How do you perform authentication in Rest Assured?

You can perform basic authentication like this:

given()
.auth()
.basic(“username”, “password”)
.when()
.get(“/secured-endpoint”);

Explain how to handle cookies in Rest Assured.

To extract cookies from a response:

Response response =
given()
.when()
.get(“/endpoint”)
.then()
.extract().response();

Map<String, String> cookies = response.getCookies();

How can you set a base URI in Rest Assured?

RestAssured.baseURI = “http://api.example.com”;

Explain how to use path parameters in Rest Assured.

given()
.pathParam(“paramName”, “paramValue”)
.when()
.get(“/endpoint/{paramName}”);

What is the difference between given(), when(), and then() in Rest Assured?

  • given(): Sets up preconditions or request specifications.
  • when(): Specifies the action you want to perform (e.g., GET, POST).
  • then(): Specifies the validation or assertions to be made on the response.

How do you perform multiple validations in a single request in Rest Assured?

given()
.when()
.get(“/endpoint”)
.then()
.assertThat()
.statusCode(200)
.body(“key1”, equalTo(“value1”))
.body(“key2”, equalTo(“value2”));

Explain how to send a PUT request in Rest Assured.

given()
.contentType(ContentType.JSON)
.body(“{\”key\”: \”updatedValue\”}”)
.when()
.put(“/endpoint”);

How do you handle response headers in Rest Assured?

To extract a specific header:

Response response =
given()
.when()
.get(“/endpoint”)
.then()
.extract().response();

String contentType = response.getHeader(“Content-Type”);

Explain how to send a DELETE request in Rest Assured.

given()
.when()
.delete(“/endpoint”);

How do you perform parameterized testing in Rest Assured?

You can use TestNG or JUnit parameterized tests to run the same test with different inputs.

What is the difference between given().param() and given().queryParam() in Rest Assured?

  • given().param(): Used for sending request parameters in a GET request.
  • given().queryParam(): Used for sending query parameters in a GET request.

Explain how to handle request headers in Rest Assured.

You can add headers to a request like this:

given()
.header(“HeaderName”, “HeaderValue”)
.when()
.get(“/endpoint”);

What is the purpose of the log() method in Rest Assured?

The log() method is used for logging request and response details. It helps in debugging and understanding the flow of requests and responses. For example:

given()
.log().all()
.when()
.get(“/endpoint”);

Explain how to validate a JSON response with dynamic content using Rest Assured.

You can use the Matchers class to perform dynamic content validation. For example, to check if a response contains a specific key:

given()
.when()
.get(“/endpoint”)
.then()
.body(“key”, Matchers.notNullValue());
google-news
Avinash

Avinash is the Founder of Software Testing Sapiens. He is a blogger and Software Tester who has been helping people to get thier Jobs over a years Now.

Leave a Comment

whatsapp-icon
0 Shares
Copy link