Most of the time we have used all the static method of REST Assured using Class reference of REST Assured classes
But we can use the static method of REST Assured classes using static import.
import static io.restassured.RestAssured.given;
Now we can use given() method directly no required of RestAssured to access given() method
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
public class ValidateAPI {
@Test
public void validateSimpleAPI() {
RequestSpecification requestSpecification = new RequestSpecBuilder().setBaseUri("http://restapi.demoqa.com/utilities/weather/city/")
.setContentType(ContentType.JSON)
.addFilter(new CustomLoggingFilter())
.build();
given(requestSpecification).when().get("/Hyderabad").then();
}
}
But we can use the static method of REST Assured classes using static import.
import static io.restassured.RestAssured.given;
Now we can use given() method directly no required of RestAssured to access given() method
import org.testng.annotations.Test;
import static io.restassured.RestAssured.given;
import io.restassured.builder.RequestSpecBuilder;
import io.restassured.http.ContentType;
import io.restassured.specification.RequestSpecification;
public class ValidateAPI {
@Test
public void validateSimpleAPI() {
RequestSpecification requestSpecification = new RequestSpecBuilder().setBaseUri("http://restapi.demoqa.com/utilities/weather/city/")
.setContentType(ContentType.JSON)
.addFilter(new CustomLoggingFilter())
.build();
given(requestSpecification).when().get("/Hyderabad").then();
}
}