So, I already know the SFDC proscribed route for testing callouts.

The code I'm testing is rather more sophisticated than SFDC's example. Instead of returning a String, I'm returning a data transfer object (DTO), so to build a response for the mock, my code is like this:

ResponseDTO dto = new ResponseDTO();
dto.accountList = TestAccountFactory.createList(5);
response.put('response_x', dto);

However, going this route, it is easily observed I am never dealing with the actual XML being returned by the server.

I have been instructed to test how the system handles a specific message back from the server. For argument's sake, let's say:

<abc:response someAttrib="123">
     <def:someValue anotherAttrib="456">Blah blah blah</def:someValue>
</abc:response someAttrib="123">

I don't want to deserialize this in my mock since then I'm testing the mock or my testing framework and not the system itself.

Is it possible to develop a test which will allow me to mock the server's response instead of the handled server response?

If so, how?

Also, what arguments, either for or against, might be offered against the proposition that such a test is more of a test of SFDC than our project?

  • Why would you not want to put it in your mock? You code needs to handle the response, you are not testing the external server. The best way I have seen to test mock responses and create them without having to modify your mock class is here: salesforce.stackexchange.com/questions/141330/… - I do not understand what the hesitation is to using that XML as a response to test your code – Eric Apr 20 '17 at 20:59
  • First, I'm not testing an HttpCallout but a WebServiceCallout. Second, I DO want to put the XML into my mock. What I don't want to do is put the processing of the XML into my mock. If I put the process into my mock, then I might as well just skip to the result of the process since my test wouldn't be testing the process or I'd be testing test code instead of production code. – Brian Kessler Apr 20 '17 at 21:30
  • Same concept applies for webserviceMock just change the return types etc. You generate the XML in your test, passing to the mock when you instantiate it. No other way around it, you have to specify the response and this modal is the most flexible – Eric Apr 20 '17 at 21:32
  • I'm not debating against the need to specify a response, I'm just not entirely clear on the code which will allow me to specify the response as XML instead of an object and transform the XML within the mock but rather leave the transformation to the system. – Brian Kessler Apr 20 '17 at 21:46
  • I don't believe a direct XML response from the mock is possible. I've tried in the past. The response Map won't accept the XML for a value, it will insist on an Object with the expected response type that WebServiceCallout.invoke can deserialize. – Daniel Ballinger Apr 20 '17 at 23:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.