You don’t want your tests to make requests on a production server and a separate test instance is costly, so you have two realistic options:
Both approaches require similar efforts in terms of preparing fake responses, but the mocking approach has two major problems:
With a fake server, you don’t need to touch your client or adapter code at all. You don’t even need to know how the code works to test it, enabling black-box testing. If you forget an endpoint, the fake server will raise an error. Another nice benefit is that the fake-server tests will force you to properly separate code from configuration: you need to be able to pass in a different set of URLs, otherwise this approach won’t work.
For Python, pytest-httpserver
is a nice option if you use pytest
.↩︎