Rest Assured introduction
Rest-Assured is a Java based library that is used to test RESTful Web Services. This library
behaves like a headless Client to access REST web services
Rest Assured simple java libraries for testing of Rest WebServcie API
Rest-Assured library also provides ability to validate the Rest-HTTP Responses received from
server. For e.g. we can verify the Status code, Status message, Headers and even the Body of
the response. This makes Rest-Assured a very flexible library that can be used for testing.
It support both XML and JSON
Why RestAssured is popular?
It Can Integrate seamlessly with existing java based framework like
Testing/junit/BDD
Selenium Webdriver
JDBC
So that We can Automate E2E business workflow which include all the layers
Rest assured Advantages
Support for all http methods
Support for BDD [given(), when(), then()]
Use of Hamcrest matches for validation /Assertions
Provide inbuilt method to create a request header & body
Provide inbuilt method to validate response header & body
Handles various authentication like Token AUTH, Basic auth , oauth1.0 , oauth2.0
Send request over the network using existing protocol like http
Integrate seamlessly with existing java based framework like selenium, testng , jdbc , poi etc
Used for complete backend automation
Framework can integrate with CI/CD pipeline
Open source headless client
Rest assured Project Setup
In order to use Rest assured client ,we should create a maven project & add below
dependency
Step to create maven Project
open Eclipse
create maven project
Add below dependency in POM.xml
save pom.xml file
Tool Description
rest-assured-3.0.2 Rest api backend automation
json-simple-1.1.1 Used to create Json object
jackson-mapper-asl-1.9.13 Used to create pojo & parser class
testng-6.8 Unit testing tool
Mysql Used for database connection & automatio
Selenium-java Used for Web Browser automation
Rest assured Class diagram
Description of Every API
Rest Assured class Description
Main class of restassured , where we can start the Rest API test using
RestAssured BDD like given(), when() , then()
RequestSpecification Used to set the specification of the request like authentication & parameter etc.
RequestBuilder Used to create common reusable precondition code for the request
RequestSpecSender Used to set precondition for the request
Response Used to receive the response of the request
ResponseSpecification Used to set the specification of the response
ResponseSpecBiuilder Used to create common reusable precondition code for the request
ValidateResponse Used to validate the response
JsonObject used to create JSONObject
ObjectMapper used for serialization