I've developed an SDK (link) for a RESTful API in PHP, and my automated tests (example) are actually live calls against the API, which is bad for multiple reasons, mainly:
- it takes a long time (about 3 hours) for the tests to complete
- it's impossible to do concurrent tests because they'll interfere with each other
I want to stop making live API calls.
I have an idea:
- short circuit the request before it's fired
- assert that the request URL is correct, in a way that, for example, if I pass a value
John
to thefirst_name
param, I'd expect the request URI to containfirst_name=John
. Also, I have to be wary about optional params.
However, I don't think this is a full replacement because I lose the robustness of the response.
How do I know that the request is, in fact, valid without making a live call and checking the response code or JSON response?
Right now the library is using a random HTTP lib, but in the next major release which I'm working on right now, I will switch to Guzzle, which does support testing and short circuiting the request.
Finally, you can see an example of the API response here: https://reference.assemblypayments.com/#create-item
How do I know that the request is, in fact, valid without making a live call and checking the response code or JSON response?
-- You can't. However, if your software components are sufficiently decoupled, you can test each component independently.