All subjects

API Testing · Interview subject

REST Assured Interview Questions

Given/when/then, specs, schema validation, POJO serialisation and auth.

53 questions

Quick interview answer

Use JSONPath expressions in body() matchers, or deserialize into a POJO and assert on typed fields.

Detailed explanation

For a couple of fields, inline Hamcrest matchers are fastest. For a large payload reused across tests, deserialize with Jackson into POJOs — you get compile-time safety and reuse. Add JSON schema validation to guard the contract shape itself.

java
1Response res = given().spec(SPEC).pathParam("id", 7)
2 .when().get("/orders/{id}")
3 .then().statusCode(200)
4 .body("customer.address.city", equalTo("Bengaluru"))
5 .body("items.findAll { it.qty > 1 }.size()", greaterThan(0))
6 .body(matchesJsonSchemaInClasspath("schemas/order.json"))
7 .extract().response();
8
9Order order = res.as(Order.class);
10assertThat(order.total()).isEqualByComparingTo("2499.00");

Real-world example

Order service returning nested customer, address and line-item arrays.

Interview tip

Mention schema validation unprompted — it signals contract-testing awareness.

Next subjectFramework Design