API Testing Strategy using Java Rest Assured and BDD (Cucumber) framework

Aceautomationacademy
3 min readFeb 15, 2024

--

****Detailed explanation and github link provided****

Web application is something which is visible to the users through their eyes and they are able to see some images, texts, buttons, selections which is appearing on the frontend which is also called as GUI (Graphical user interface) and they can perform some user actions. What's not visible in an application to the users is the backend — which is largely driven by APIs (Application programming interface). APIs takes care of security, database calls, interfacing with 3rd party systems

In organisations as per the development life cycles : apis are something which gets designed and developed before the user facing front end side.
What it means for us Automation engineers, analysts and architects — testing early is something which is very important hence its evident we test apis before we test the GUIs.

Why is API so important for us — as it communicates

Different verbs related to API:

GET
POST
PUT
DELETE

What to test in Apis? Testing strategy.
When Apis are called its an HTTP transaction with request being sent by client and response being received back. Its important to validate Response Code & Response Body.
Response codes
needs to be validated to verify whether the transaction was successful or not — which is important. Response Body needs to validates to verify if the transaction which was received was as per the agreed contracts and interface design or not — which is also equally important.
Each test is comprised of test actions. These are the individual actions a test needs to take per API test flow. For each API request, the test would need to take the following actions:

1. Verify correct HTTP status code. For example, creating a resource should return 201 CREATED and getting resource should return 200 OK.

2. Verify response payload. Check valid JSON body and correct field names, types, and values — including in error responses.

3. Verify all the VERBS (GET, POST, PUT, DELETE) — all the transactions are validated — and reuse the code whereever possible.

4. Verify response headers. HTTP server headers have implications on both security and performance.

5. Verify correct application state. This is optional and applies mainly to manual testing, or when a UI or another interface can be easily inspected.

6. Verify basic performance sanity. If an operation was completed successfully but took an unreasonable amount of time, the test fails.

Test Automation Design
we can easily devise an automation framework using Java and Rest Assured to test the APIs — which helps to perform tests to verify the stability of the apis before it get integrated with the front. Test Automation framework is important to maintain reusability, scalability and maintainability. we can still add new tests as well as modify the existing tests using the framework. Most widely used test automation framework is BDD (Behaviour driven framework) which is easily understandable by the users, nontechnical members as well as business analysts. BDD framework are designed in the format of features, scenarios and Given, When, Then format.

Scenario:
Given
When
Then

Cucumber library helps us to structure the tests as per the requirement — using features and java step definitions helps us to make the http request calls and save the responses to validate.

Java as the programming language
Maven as the project for library management
Cucumber as the bdd framework
IntelliJ as the Integrated development framework
Rest Assured as the Java libraries for http transactions.

detailed tutorial has been uploaded in the below youtube link:

and the github link with Readme document.

Thanks for reading !

We are team of passionate techies — who help to share knowledge within our community — if you like our content — kindly follow, share and subscribe.

--

--