views:

27

answers:

1

The method I want to test has a local variable that references an object returned from a Web service call. This Web service returns information specific to a particular user based upon input from that user on a Web page. It is like a question/answer, where the answer given in a form text field must match the answer provided by the user at an earlier date, and is now tied from their account. There are certain things that happen based upon whether or not they got the answer correct. Should I mock out the service as a field on the class instead, where I can set it to return a dummy service response, or is there a better way to test it? Thanks!

+4  A: 

I think your intuition is good on this one, to mock out the service.

McWafflestix
I agree. It's a unit test. Isolate the subject under test from other dependencies.
erickson
Exactly. You can test the other dependencies independently.
McWafflestix
JMock might be helpful for this.
Vincent Ramdhanie