REST API testing using JS

Photo by Nathan Anderson on Unsplash

Required tools

To set up API testing functionality we’ll need:

  • mocha — a simple and fun testing framework :)
  • chai — BDD / TDD assertion library

Endpoint test suite example

As you may know, each REST API endpoint can have different methods, applied to it.

  • GET — for getting the list of created users
  • PUT — for editing user
  • DELETE — for deleting user

Endpoint tests example

Each API test is always easy to implement because most of the time it’s just about 3 operations:

  1. Make request
  2. Check response

Test run reports and CI / CD integration

CI integration is as easy as possible :)

  • If some tests are failed, the Dev team receives notification, with all the needed information (environment, logs, test results etc.)

Summary

In this article, I’ve shown you an example of how REST API testing can be performed using JS and its free tools.

--

--

QA Lead. Love Ukraine, my Family, Javascript and Quality Products.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Andrii Ievtukhov

Andrii Ievtukhov

QA Lead. Love Ukraine, my Family, Javascript and Quality Products.