Reputation: 187
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.
Upvotes: 3
Views: 7171
Reputation: 303
Firstly you need to fix the code and make sure about two imports.
import io.restassured.RestAssured;
import static org.hamcrest.Matchers.equalTo;
public void testGetSingleUser() {
given().
expect().
statusCode(200).
body(
"email", equalTo("[email protected]"),
"firstName", equalTo("Tim"),
"lastName", equalTo("Testerman"),
"id", equalTo("1")).
when().
get("/service/single-user");
}
And make sure to add JARs.
Upvotes: 0
Reputation: 1
We use RestTest it's an easy free standalone app.
Add all your urls in one file and test conditions. One line One Test :)
Upvotes: 0
Reputation: 163
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;
Upvotes: 7