1

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?

7
  • 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, 2017 at 20:59
  • 1
    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. Apr 20, 2017 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, 2017 at 21:32
  • 1
    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. Apr 20, 2017 at 21:46
  • 1
    @DanielBallinger, I'd be curious to see your generated Apex, but it sounds to me like including it would fall on the wrong side of the divide between the test code and the production code. Apr 21, 2017 at 5:06

0

You must log in to answer this question.

Browse other questions tagged .