What is the best way to write unit tests for a REST API?

When writing unit tests for an API shell, should I make real calls to REST API endpoints or use mocl responses that mimic successful and failed calls?

+7
source share
1 answer

Unit tests mean testing only your device (API wrapper), nothing more. So, unfortunately, you have to make fun of the whole API.

On the other hand, this never gives me enough confidence, so I go for system tests (also known as component tests). In this case, you should run your API shell against an existing API, possibly built-in, and start with your test. In the integration test, in the end, you run your API shell against the real, but most likely test instance of the API (sandbox, development environment).

In the well-established field of database testing: unit tests determine the entire DAO level, component tests run against the database in memory, while integration tests connect to a real database with some fake data.

+11
source

All Articles