I am new to REST-Api testing. i am getting started with Rest-Assured for Rest-Api testing. i am having an issue in my first ever testcase.
The code is as follows:
public void testGetSingleUser() {
expect().
statusCode(200).
body(
"email", equals("[email protected]"),
"firstName", equals("Tim"),
"lastName", equals("Testerman"),
"id", equals("1")).
when().
get("/service/single-user");
}
In this code the "expect()." command is not working. I need to fix this issue quickly and move on.
Your request can't compile because you forget given() and you have to use equalTo() instead of equals().
Try this request:
given().
expect().
statusCode(200).
body("email", equalTo("[email protected]")).
body("firstName", equalTo("Tim")).
body("lastName", equalTo("Testerman")).
body("id", equalTo("1")).
when().
get("/service/single-user");
Also double check your imports:
import static com.jayway.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With