Skip to content

Repository files navigation

API Testing using SuperTest, Mocha and Chai

License Node.js CI

Don't forget to give a ⭐ to make the project popular.

What is it all about?

I have been using Rest-Assured framework all the time for testing APIs with Java. But this time it was my project's demand to perform API testing in Javascript. Being a newbie to JS, I googled for some tools and found SuperTest. To introduce SuperTest, it is a high level abstraction of HTTP requests, making it perfect for testing APIs. I decided to do a POC of this tool to understand it better, hence this project was created. I thought of sharing this on github, so it helps others as well who want to learn more about this tool. Checkout this link to learn more about SuperTest

Getting Started:

You need to have the following installed on your machine:

  1. Node(Latest Version).
  2. npm(Latest Version).
  3. mocha framework is used for writing tests and chai for assertions, following command should help to install the required npm packages: npm i -D -g supertest mocha chai mochawesome
  4. For running the tests, you need to type the command: npm run test. (Check Package.json for more details)
  5. For generating the mochawesome report, run the command npm run html-report (Check Package.json for more details.) It will generate and export the report in mochawesome-report folder from which you can open the index.html file to view the report.

Talking more about the Scenarios Covered in this project:

  • I have covered, GET, POST, PUT, PATCH and DELETE requests. The example code is available in the test folder of the repository.

  • End to End scenarios have been added for the restful booker APIs. Check out API Testing with superTest for more details.

  • Mochawesome reporter is used to generate the reports and show summary of the tests. I found it quite useful report as it shows the test description along with the tests and the time taken to run the tests.

❓ Need Assistance?

  • Discuss your queries by writing to me @ mohammadfaisalkhatri@gmail.com OR ping me on any of the social media sites using the below link:

💻 Paid Trainings

  • Contact me for Paid trainings related to Test Automation and Software Testing, mail me @ mohammadfaisalkhatri@gmail.com or ping me on LinkedIn

💭 Checkout the Software Testing Tutorials, articles and Videos:

Packages

Used by

Contributors

Languages