-
Notifications
You must be signed in to change notification settings - Fork 67
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
Tests should run against mock http responses #5
Comments
Hi Doug That's exactly what I though a while ago, actually my another project, couchcache, does something similar. However I didn't feel secure mocking responses from service provider. One recent example is, I realised MapQuest Nominatim introduces an access key months after they did it. Live tests reduce the value of their mocking counterpart in most cases. But the intermittent build failure is definitely something needs to fix. Cheers |
I agree that mocking responses adds a potential layer of code rot if the API's change or some part of it changes e.g. requires API key, but then again the same could happen with the API tests in the sense that if the external API changes the tests don't automatically run (because they only run on code changes in this repo). I think it might make sense to have both tests, if for nothing else it makes it easier for contributors to submit PRs and have test verification run (because travis-ci can't run PR builds using the encrypted API keys because it'd be a security risk because a PR could I like to think that the project could have 2 types of tests:
It could be that we "record" the results of the integration test runs as input for future unit tests, and we could have a process to sync that so we could keep it up to date. I might explore those options and see how it looks and we can figure out if it'd make sense to add it (I definitely agree there's a trade off of adding the complexity/maintenance of mock HTTP testing vs just verifying against the real HTTP API). |
I love the idea of connecting the 2 types of tests, by (regularly) sourcing the real life responses from integration tests to unit tests. |
https://godoc.org/github.com/orchestrate-io/dvr sounds like an interesting way to handle HTTP testing, basically you can run it in Record HTTP Test Responses
Playback HTTP Test Responses
|
Hi @dougnukem, Tests will call real server if optional parameter is not available. |
Cool @codingsince1985 that looks like a great start, we can start with that (I think it'll be really helpful if there are community contributions so that the travis-ci tests can at least run against some example responses). I was thinking we could toggle using the test HTTP data based on if there is an API key e.g. I made an attempt to use the https://godoc.org/github.com/orchestrate-io/dvr library which will record requests automatically, but playing them back got weird because it expected exact requests (which included API keys). I do like the flow of the dvr library where you run the unit tests with a flag and it'll record the test HTTP requests and responses, it just needs a little more configurability on the playback. |
dvr does look promising, though |
closed via #27 |
Testing would be easier to perform and more reliable if the library used mock http responses for geo APIs (e.g. the API's seem to be a little flakey sometimes causing intermittent build failures).
We could record HTTP requests/responses from the existing tests as the initial mock http responses.
We could always conditionally run the tests in "integration" mode which would run the mock tests and actual API tests if we still wanted to exercise the live APIs.
The text was updated successfully, but these errors were encountered: