xxxxxxxxxx
public class RestAssuredExample {
@BeforeClass
public void setup() {
// Set the base URI for your API
RestAssured.baseURI = "https://jsonplaceholder.typicode.com"; // Example API
}
@Test
public void exampleTest() {
// Perform a GET request to "/todos/1"
given()
.when()
.get("/todos/1")
.then()
.statusCode(200) // Verify that the response status code is 200 (OK)
.body("userId", equalTo(1)) // Verify that the "userId" field is equal to 1
.body("id", equalTo(1)); // Verify that the "id" field is equal to 1
}
}
xxxxxxxxxx
RestAssured: is a library for testing restful API programmatically.
it use a library called Hamcrest for aserting the response
import static io.restassured.RestAssured.* ;