I have never used JUnit or other testing frameworks. All i know is how to develop rest service. I recently saw REST assured framework to test REST api. But all the articles that i found looks like below. But i don't know how to pass request xml and how will i get response and when should i call this method.?
Do i need to use some other tool before this REST assured.? I am completely beginner in this kind of testing frameworks. Please show me some light in this world. All i know is how to send request and check values in the response in SOAPUI. I have never tried this.
expect().
statusCode(200).
body(
"user.email", equalTo("[email protected]"),
"user.firstName", equalTo("Tim"),
"user.lastName", equalTo("Testerman"),
"user.id", equalTo("1")).
when().
get("/service/single-user/xml");
REST Assured is an open-source, Java-based library to test REST web services. REST assured does not have a GUI and supports XML & JSON. REST Assured works in three simple steps and automated test scripts are written. A Java class consists of the HTTP method while an XML file is responsible for executing the Java class.
Rest assure or Rest assured? “Rest assured” is correct. In this case, we need the adverb form of the word “assure” so “assured” is the correct form. When people speak “rest assured” it can be difficult to hear the “d” sound at the end of the word.
Rest assured that: It's generally used when there are issues or problems and somebody is worried about them. This phrase is a way to reassure the person receiving the email/letter that you will resolve or deal with them, e.g. 'Rest assured that there is no risk to your investment'.
expect() /* what u expect after sending a request to REST Service */
statusCode(200) /*you are expecting 200 as statuscode which tells request handled successfully at server */
body() /* the conditions given in body are compare the value with expected values. "equalTo" hamcrest matcher condition (you need to have hamcrest jar in java classpath).*/
when(). /* as is name says above all will be done after sending get/post/put/delete request right so before you put these get,post,put,delete you will have this method as prefix */
get("/service/single-user/xml") /* the actual REST API request url goes here. can be GET/POST/PUT/DELETE. the confusion for you is its only showing half part which is base path.you can give entire request url in get() method.*/
more on: http://rest-assured.googlecode.com/svn/tags/1.8.1/apidocs/com/jayway/restassured/RestAssured.html
I hope this helps.
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