How to measure and validate API response time? code example

Example: rest assured time response

import org.testng.annotations.Test;

import io.restassured.builder.RequestSpecBuilder;
import io.restassured.response.Response;
import io.restassured.specification.RequestSpecification;

import static io.restassured.RestAssured.given;

public class ExampleTest {
	@Test
	public void getResponseTime() {
		RequestSpecification requestSpec = new RequestSpecBuilder().build();
		requestSpec.baseUri("http://localhost");
		requestSpec.basePath("user/details");
		Response response = given().spec(requestSpec).get("/10");

		// Print response time
		System.out.println("Response Time : " + response.getTime());

	}
}

Tags:

Misc Example