'header' method is used to Validate the Response Headers. For example, below snippet verifies response content type.
Example
given().header("Accept", "application/json")
.when().get("api/v1/employees/")
.then().assertThat().statusCode(200).and()
.header("Content-Type", "application/json;charset=UTF-8");
package com.sample.app;
import static io.restassured.RestAssured.given;
import org.junit.Test;
import io.restassured.RestAssured;
public class TestApp {
@Test
public void testApp() {
RestAssured.baseURI = "http://localhost:8080";
given().header("Accept", "application/json").when().get("api/v1/employees/").then().assertThat().statusCode(200)
.and().header("Content-Type", "application/json;charset=UTF-8");
}
}
This post first appeared on Java Tutorial : Blog To Learn Java Programming, please read the originial post: here