RestAssured Response & Request Specification Simplified | Easy Breakdown
These are used to avoid duplication of code for reusable configurations that need to be done for multiple RESTful request and response validations.
Now just by reading above we can understand, if we have multiple tests that revolve around similar usage of baseUri, headers, cookies, authentication etc. then its better to create a separate function which executes before our tests. This will provide a base setup for each Test.
Now let’s quickly understand how it works:
RequestSpecification
In the above screenshot, we can easily see BaseUri, basePath, filters and logs are used as part of request specifications. With this now, I can directly incorporate this requestSpec function, in all my API tests. Without re-writing the same code.
From above image, we can understand, I am reusing the requestSpec. But we can also view certain data like body, headers are still kept separate just because they can be different for each API request/test. Hence we need to evaluate what can be the common details for each API request/test.
Similarly, we can incorporate the use ResponseSpecification like below:
ResponseSpecification
Major advantages of using Request & Response Specification:
- Abstraction of requests and responses
- Better readability for code
- Reduces code complexity & repetition
-x-x-
Learn, implement API Testing & API Automation from scratch using Postman, JAVA & RestAssured: Link
SDET Interview Q&A for 2024: Link
#japneetsachdeva