-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add tests for ease #13
Comments
I think that for testing, it makes sense to separate the request logic from the logic that processes responses. That is, to have a function I suggest against unit testing for the functions that actually do the request. Instead, I would test those functions by actually running a server locally for the test. That way, you can check that you have gotten the URLs right and so on. Does this sound reasonable to you? If so, we could just add some helper functions to create mock responses. |
Thanks for your input @simonpersson 😃 Yes, starting a test webserver is a quick and simple way to test that the whole request-response cycle works. As in my case I just wanted some lightweight unit tests where I could simply have some mock response JSON string and see if my internal type conversion and error handling works. Something like hyper does internally or yup-hyper-mock. In the end we might want to have both, integration and unit tests. Most importantly we both agree that we want a simple and straightforward way to test things... with ease. 😉 |
For testing an API client which uses ease, I'd like to mock a server response with some predefined JSON data. For example, each request to http://example.com/endpoint would return
I could then use this response in my assertions.
Now, one way to achieve this would be to expose hyper's
Request::with_connector(method, url, &connector)
in ease.The connector would then be a mock and could return the "fake" response on every request.
Here is some sample unit test from within hyper which uses this mechanism.
As you can see this unit test is currently commented out, so I'm not sure if the behavior has changed and if this is still possible. Nevertheless it would be awesome to be able to test libraries that use ease - and probably ease itself. I would be very happy for any suggestions on how to achieve this.
The text was updated successfully, but these errors were encountered: