Using
'assertThat' method, we can validate response codes, response body etc.,
Below
snippet validate the response code.
given().header("Accept",
"application/json").when().get("api/v1/employees/").then().assertThat().statusCode(200);
TestApp.java
package com.sample.app;
import org.junit.Test;
import static io.restassured.RestAssured.given;
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);
}
}
Run
TestApp as Junit Test.
If you are
using Eclipse, Right click on TestApp.java -> Run As -> Junit Test.
Once you ran the application as Junit Test, you can see the status (whether test case is passed or failed) in Junit window.
No comments:
Post a Comment