How to Automate API Tests?

In Software Development, having proper Quality Assurance procedures is paramount to projects being successful. In this post, I briefly explore tools that help automate API Testing.

How to Automate API Tests?

In Software Development, having proper Quality Assurance procedures is paramount to projects being successful. Earlier in my career, I've worked on numerous products which were developed without automated testing. As a result, things broke all the time and delivery time was always postponed as it took us a lot of time to search where the issues were and correct them without breaking something else.

With Automated Testing, whenever you have a new release, you can check if things are breaking before going onto production. In fact, you can even run these tests while you are developing so that you can avoid bugs due to the regression issues.

API

With more software being developed and shared across organisations, partners and the public, APIs are becoming more and more relevant. Nonetheless, having ways to test them remains as important.

As I am myself researching tools to automate API testing, here is a quick list I'm researching.

Postman

Postman is a collaboration platform for API development. Postman's features simplify each step of building an API and streamline collaboration so you can create better APIs—faster.

You can write test scripts for your Postman API requests in JavaScript. Tests allow you to ensure that your API is working as expected, to establish that integrations between services are functioning reliably, and to verify that new developments haven't broken any existing functionality. You can also use test code to aid the debugging process when something goes wrong with your API project. [1]

You can run your API requests and test if the response contains expected properties and values.

For me the biggest advantage of using this tool is the shallow learning curve especially if you're well versed in JavaScript. There is also lots of documentation with examples on how to write and run your tests.

Cypress

Cypress is a next generation front end testing tool built for the modern web. We address the key pain points developers and QA engineers face when testing modern applications. [2]

With Cypress, you can not only perform Unit or End to End Tests, but also test your APIs.

https://dev.to/leading-edje/api-testing-with-cypress-4p8n
https://dev.to/leading-edje/api-testing-with-cypress-4p8n

For me Cypress is the best Web Automation tool as it comes with batteries loaded such as a test runner and an interesting UI for displaying the test results.

Rest Assured

Rest Assured is one of the most recommended solutions for Automating API testing. It makes testing Rest Services easy in Java, which highly in demand in Enterprise Software Development.

It's easy to get started especially with Maven: just add the dependency and start using it.

https://rest-assured.io/

xUnit & RestSharp

xUnit is an excellent testing tool for the .NET framework. Along with RestSharp, it's easy to setup and get started on testing APIs. This is a great duo for any organisation already using .NET.

https://xunit.net/
https://restsharp.dev/


References

[1] - https://learning.postman.com/docs/writing-scripts/test-scripts/

[2] - https://docs.cypress.io/guides/overview/why-cypress