pytest fixture to mock HTTPX
I avoid writing automated tests that hit an external API - especially one out of my control - because I don't want my CI runs to ever fail because someone else's service wasn't responding. I want CI to be a completely closed box, such that any failures mean there's a bug in my code.
If I want to test external APIs I'll do that in a separate set of integration tests which are run as part of a separate system, not as part of my CI for every code commit to my repo.
I mostly use Python, and the APIs I talk to are mostly accessed via the requests or httpx libraries - both of which have excellent libraries for productive mocking:
Ginkgo's Preferred Matcher Library
Depends on the API and how much testing you need. You want to test your code, not the API's availability or correctness.
But it can be as easy as using a fake http library and mocking the responses, or using a httptest server: https://onsi.github.io/gomega/#ghttp-testing-http-clients
If the API is complicated and you have to write your own fake server, that might not make sense for small projects.
Collect and Analyze Billions of Data Points in Real Time. Manage all types of time series data in a single, purpose-built database. Run at any scale in any environment in the cloud, on-premises, or at the edge.
2 projects | dev.to | 23 Nov 2023
Testing Express API Routes the Easy Way: Beginners' guide.
3 projects | dev.to | 19 Nov 2023
In-Depth guide for TypeScript Library
4 projects | dev.to | 13 Nov 2023
Cypress changed older versions to block third-party plugins (ignoring lockfiles)
2 projects | news.ycombinator.com | 8 Nov 2023
How To Write Better and Quality Code
5 projects | dev.to | 5 Nov 2023