How can I unit test a class which requires a web service call?

Posted by Chris Cooper on Programmers See other posts from Programmers or by Chris Cooper
Published on 2013-10-11T14:26:38Z Indexed on 2013/11/11 10:24 UTC
Read the original article Hit count: 357

I'm trying to test a class which calls some Hadoop web services. The code is pretty much of the form:

method() {
    ...use Jersey client to create WebResource...
    ...make request...
    ...do something with response...
}

e.g. there is a create directory method, a create folder method etc.

Given that the code is dealing with an external web service that I don't have control over, how can I unit test this? I could try and mock the web service client/responses but that breaks the guideline I've seen a lot recently: "Don't mock objects you don't own". I could set up a dummy web service implementation - would that still constitute a "unit test" or would it then be an integration test? Is it just not possible to unit test at this low a level - how would a TDD practitioner go about this?

© Programmers or respective owner

Related posts about unit-testing

Related posts about TDD