This is a full-fledged tutorial on Rest API Automation testing using one of a very popular Java-based API i.e ‘Rest Assured‘ library. It is in high demand among automation testers. In this guide, we are going to present solutions that are easily understandable and quick to implement and use. This rest assured tutorial is not only for beginners but for advanced users as well.
Rest Assured is a Java-based library. It is one of the most popular libraries to test RESTful Web Services and used to perform testing and validation of Rest Services with simplicity. It can be considered as a wrapper implementation of the HTTP client library as it underneath performs the same operations as what HTTP client API does. RestAssured API is highly scalable and customizable and can be really effective to create extensive Requests to tests a particular service.REST Assured Tutorial for REST API testing for beginners as well as advanced users...!!! Click To Tweet
It provides a BDD-like structure to write the code that is one of the advantages of using it as it makes it simple to use.
As I’ve mentioned above that it is an implementation over the HTTP Client library, therefore, it would be simple to write the code in the REST-ASSURED as it is more refined and high level.
As it is a Java-based library, so it would be very easy to integrate with the UI test code in the automation testing framework.
Also, in this particular guide, we are going to use JSONPath for JSON manipulation and Hamcrest API for assertions.REST Assured Tutorial for REST API testing for beginners as well as advanced users...!!! Click To Tweet
Let’s have a look at REST-assured Syntax:
Let’s give you a brief idea here about how the above-mentioned code operates:
a. As per the above example, there is no method been passed to ‘given‘. It means there are no specific preconditions there.
b. There is a ‘get’ method which is being passed to ‘when‘ and it signifies that when we are hitting this URL present in the ‘get’ method, an event occurs.
c. When we hit the URL in ‘when’, ‘then‘ we are going to receive output as a response, and then we perform validation on it. Here in this particular example shown in the above image, we are performing an assertion on the body by validating the size of a specified element.
Let’s jump on the thorough REST Assured tutorial for beginners/advanced users, here we are going to cover the below topics:
- Configure Eclipse with Rest-Assured
- REST API Endpoints Test using Rest Assured
- GET Request Endpoint Testing
- POST Request Endpoint Testing with JSON as Request Body
- PUT Request Endpoint Testing with JSON as Request Body
- DELETE Request Endpoint Testing
- Passing Query parameters in Rest Assured
- Handling Path parameters in Rest Assured
- Serialization and De-Serialization in Rest Assured
- JSON Schema Validation using Rest Assured
- POST XML Request using Rest Assured
- Basic Authentication using Rest Assured
- Upload File using Rest Assured
- Parse JSON Response in Rest Assured
Other Useful References:
Deepak Verma is a Test Automation Consultant and Software development Engineer for more than 10 years. His mission is to help you become an In-demand full stack automation tester.
He is also the founder of Techndeck, a blog and online coaching platform dedicated to helping you succeed with all the automation basics to advanced testing automation tricks.