Reputation:
as the subject goes, how do you do your unit tests when an method is required to do a http request?
I'm thinking specific about some kind of class thats wrapps curl functionality.
I could use some service like http://httpbin.org/, but then it is required that you have an internet connection when you run your tests.
Or i could have some kind of server locally that do the same.
but i dont know whats the best solution is.
how do you guys handle a situation like this?
:)
Upvotes: 0
Views: 385
Reputation: 39278
The most common way to unit test this type of functionality is to abstract the http endpoint through mocking or general code abstraction (interfaces, dependency injection etc). It's not considered a pure unit test if you interact with systems outside the code under test.
The other alternative is to create what's called an integration test where you actually hit the http endpoint from your tests. You may choose to set up a testing version of the http endpoint if you go down that path. This is largely dictated by each specific scenario.
Upvotes: 3