Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use REST assured?

Tags:

rest-assured

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");
like image 826
Manoj Avatar asked Nov 19 '13 01:11

Manoj


People also ask

How does REST assured work?

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.

Can I say I REST assured?

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.

How do you send a REST assured email?

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'.


1 Answers

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.

like image 166
dileepvarma Avatar answered Nov 13 '22 22:11

dileepvarma