Sunday 24 November 2019

Rest Assured: Validate Response Headers

'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");

TestApp.java

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");

    }

}



Previous                                                    Next                                                    Home

No comments:

Post a Comment