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!
views:
27answers:
1
+2
Q:
What is the best way to write a JUnit test against a method signature that calls a Web service?
+4
A:
I think your intuition is good on this one, to mock out the service.
McWafflestix
2009-11-10 17:07:45
I agree. It's a unit test. Isolate the subject under test from other dependencies.
erickson
2009-11-10 17:13:50
Exactly. You can test the other dependencies independently.
McWafflestix
2009-11-10 17:20:39
JMock might be helpful for this.
Vincent Ramdhanie
2009-11-10 18:09:49