Last updated on November 11th, 2020 at 11:23 am
As a part of End to End REST Assured Tutorial, in this post, we will see the introduction of Rest Assured.
Demand for API Testing is increasing day by day as it helps in finding bugs early in the Software development life cycle and prevents major bugs at later stages. We can perform API Testing manually and programmatically i.e. Automation.
We have covered Manual API Testing using Postman. Now it’s time to learn about API Testing Automation using a Java library called Rest Assured.
What is Rest Assured?
REST-assured is an Open Source Java library that is used to test and validate REST APIs. Dynamic languages like Groovy, Ruby are helpful and simple to perform API testing which was harder in Java. Rest Assured is responsible to bring simplicity to do API Testing using Ruby and Groovy in Java.
REST Assured is a Java DSL for simplifying testing of REST-based services built on top of HTTP Builder. REST Assured supports any HTTP method but has explicit support for POST, GET, PUT, DELETE, OPTIONS, PATCH and HEAD and includes specifying and validating e.g. parameters, headers, cookies and body easily. It can be used to validate and verify the response of these requests.
RestAssured is built on top of Apache HTTP Client. Sometimes it is asked why not to use HTTP client directly. The below screenshot should answer this question.
REST Assured is developed and maintained by Johan Haleby. He started the project when he was working at Jayway back in December of 2010. The project is now sponsored by Parkster.
Versions of Rest Assured
Rest Assured has a legacy version as well and many beginners start using that in confusion. When you search Rest Assured dependency in Maven Central Repo then you will find two different group ids.
com.jayway.restassured – This group is legacy.
io.rest-assured – This group is the latest.
You should start learning from group id “io.rest-assured“.
Advantages of Rest Assured
- It is an Open source i.e. free.
- It requires less coding compare to Apache Http Client.
- The initial setup is easy and straightforward before you hit any endpoint.
- Easy parsing and validation of response in JSON and XML.
- The extraction of values and asserting is quite easy using inbuilt Hemcrest Matchers.
- It follows BDD keywords like given(), when(), then() which makes code readable and supports clean coding. This feature is available from version 2.0.
- Rich in syntax.
- Very rich in readymade assertions
- Quick assertion for status code and response time.
- Headers, cookies, Content-Type, etc can be verified on the fly.
- Powerful logging mechanism.
- Can be easily integrated with other Java libraries like TestNG, Junit as Test Framework and Extent Report, Allure Report for reporting purpose.
- Very good support for different authentication mechanisms for APIs.
- Can be integrated with Selenium-Java to achieve End to End automation.
- Supports JsonPath and XmlPath which helps in parsing JSON and XML response. Rest Assured by default integrates both.
- Can be used to verify JSON Schema using JSON Schema Validation library.
- Includes XML schema validation
- Can be integrated with Maven and CICD.
- REST Assured 4.1.2 is released. It adds support for Java 13.
- Supports multi-part form data
- Supports Spring Mock Mvc, Spring Web Test Client, Scala and Kotlin.
Disadvantages of Rest assured
- Does not support testing of SOAP APIs explicitly.
- Requires good Java programming knowledge
- No inbuilt reporting. Serenity BDD is a good option here.
I have started a YouTube channel as well and you can find related Rest Assured video link here:-
You can download/clone the above sample project from here.
You can subscribe to my YouTube channel RetargetCommon to learn from video tutorials.
If you have any doubt, feel free to comment below.
If you like my posts, please like, comment, share and subscribe.
Many other topics you can navigate through the menu.