In the API Testing world, if an automated testing tool doesn’t provide reusability then you will pay a great cost while maintaining the test suites over some time. Reusability and maintainability are two sides of the same coin. If reusability decreases then maintainability also decreases and vice versa. If you have a small number of APIs/test cases then reusability might not be a concern for you, but if your whole architecture is based on how to create APIs, the testing tool then reusability plays a great role while creating the automation test suites for those APIs. It is very important to think about this dimension while choosing the API automation framework/tool. We should follow the DRY (Do not repeat yourself) principle.
Reusability can be done at various levels while doing the automation test. e.g.
In vREST NG, the issue of reusability and maintainability is on top priority for us so that a great amount of effort can be saved later while maintaining the test testing suites. We have seen a lot of failed automation test efforts just due to this issue.
Next, we will see, how vREST NG handles the reusability concern.
Reusing the same test cases across scenarios
There are various test testing scenarios in which the same set of test cases or steps are repeated. It should be possible to have a single repository of test cases to avoid the duplication of requests in each workflow. Consider the following scenarios:
In the above automation test scenarios, Ist and IInd step of each scenario are duplicates. In vREST NG, instead of duplicating the steps, we can maintain a global list of steps and reuse the same steps by referencing them. So, our solution will look like this:
The way, Swagger/OpenAPI provides us the ability to define the schema definitions globally and we may reference those schema definitions in our API specs. We may even further break our schema definitions into small reusable chunks and cross-reference them. It should be possible to reuse the schemas in the same way. In vREST NG, we maintain a global list of schema definitions as it is defined in the swagger spec.
The benefits we gain with this approach are:
For more information, please read my blog post on “Easily validate your REST APIs by using the swagger definitions“.
While validating an API's positive and negative scenarios, the validation logic is mostly the same. The only thing that changes is the test input data. Negative scenarios mostly share a single JSON schema or a small set of JSON schemas. How do we handle such a scenario?
In vREST NG, we provide data-driven testing to cleanly handle this scenario. The test data is completely separated from the validation logic. This approach offers various benefits as compared to the traditional approach of API Testing.
For more information on this approach, please read this section of the vREST NG Guide on data-driven testing.
Also, you may visit this sample test data repository for data-driven testing.
Let us see, how it works. Consider various scenarios of the Update Contact API test case as below. Suppose this API accepts input for fields name, email, designation, organization.
The above list can be very exhaustive when we apply various permutations and combinations on our API input domain. If you closely look at the above test cases then you can see that the test logic is mostly the same, the only thing that changes is test input data.
With data-driven testing, we can write this test input data and partial validation logic into an excel sheet and feed that excel sheet input to our test API to validate various scenarios.
Figure: Demonstrates the close integration between Excel sheet and vREST NG Application
vREST NG provides powerful integration between the excel sheet and the application. You will just need to write your test data in the excel sheet and instantly you may run the scenarios in vREST NG Application. Even you don’t need to upload the excel sheet at all after each change or event at the beginning. vREST NG even further writes the test logic (expected response body) for you automatically in the excel sheet.
There are several situations in which test cases share a common validation logic and various utility functions are also required to generate the test input data. So, we should be able to reuse the validation logic or generic utility functions.
In vREST NG, in most of the situations, you will not need to write a single line of code. But there may be some complex situations in which custom response validation is necessary to cater your specific validation needs. We provide users the ability to write custom response validators which can also be reused across test cases. Users can also write custom utility methods which can also be reused across test cases.
Finally, Reusability is a major concern for vREST Team. We try to build each new feature with this concern in mind and try to solve the issue at its core. We designed vREST NG with these things in mind to make your API testing experience more pleasant. Just visit vREST NG website and try out vREST NG and let us know your feedback and also enlighten us to improve reusability further.
Learn how vREST NG prioritizes efficiency and maintainability, offering a seamless experience for creating and maintaining automation test suites with us. Elevate your API testing with Optimizory today!