Testing the Client Without Connecting to the API
Testing your API client by connecting to the real API is hard because you don’t always have full control over the API or the network. Even testing on your local server can be tricky because each test can impact the next. On a real live API, it’s even harder to ensure the tests are reproducible. You may also be unable to test error conditions such as invalid responses or empty lists.
In addition, it’s not nice to hit someone else’s server to test your code, especially if this is part of an automated test pipeline that runs periodically, for example, when using a continuous integration platform.
To overcome these challenges, you mock the API locally for your tests, simulating the expected responses ...
Get Powerful Command-Line Applications in Go now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.