Chapter 9: Testing an API Asynchronously with pytest and HTTPX
In software development, a significant part of the developer's work should be dedicated to writing tests. At first, you may be tempted to manually test your application by running it, making a few requests, and arbitrarily deciding that "everything works". However, this approach is flawed and can't guarantee that your program works in every circumstance and that you didn't break things along the way.
That's why several disciplines have emerged regarding software testing: unit tests, integration tests, E2E tests, acceptance tests, and more. These techniques aim to validate the functionality of the software from a micro level, where we test single functions (unit tests), to a macro level, where we test a global feature that delivers value to the user (acceptance tests). In this chapter, we'll focus on the first level: unit testing.
Unit tests are short programs designed to verify that...