Test automation framework for API testing with java

Oleksandr Podoliako
3 min readOct 7, 2022

--

Recently I have received a test task to write test automation framework for API testing with java. I think it could be interesting for others and I would like to share the results.

The framework was written with java. Maven, Lombok, testNG and Rest Assured were used. The framework consists of clients and test layers. If tests are planned to be E2E or business logic is complicated than business layer, which contains a few API clients, could be added. Also, cucumber layer could be added.

The main idea is to generalize base API client, which contains main basic API methods (GET, POST, PUT and DELETE). This gives us an opportunity to use one client to interaction almost with all endpoints. Also, it allows to configure Rest Assured log in one place through baseAPIClient

Two wrappers, which were generalized, were created to have unified approach. RequestWrapper and ResponseWrapper get their types in tests. Also, they contain raw data from the Rest Assured.

BaseAPIClient can be used to interact with different endpoints, however I recommend to create separate client for every endpoint, which inherits from BaseAPIClient main functionality. Separate API clients could be expanded with specific API methods like search and filter. Base API method from BaseAPIClient can be overridden.

I support ideas of isolation and managing state of application. You can read more about it in my previous article(Automated Testing Principles). I encourage you to create and remove test data in before and after methods. It will increase tests reliability.

I recommend writing test, which cover one REST method, in one class because the preconditions are complicated and can be different for every REST method. Also, I recommend grouping a few asserts in one test method because of optimization. The more atomic approach is valid.

The test has presentation goal and is being failed because the testing API application does not actually create and remove entities.

The full code can be found by the link — gitlab

--

--

Oleksandr Podoliako
Oleksandr Podoliako

Written by Oleksandr Podoliako

Motivated Test Automation Engineer with experience in testing web and mobile applications.

Responses (1)