Testing callouts
When we wrote the test code for our RESTful integrations, we tested by creating an instance of the HttpCalloutMock
interface that we could then use within our unit tests. For callouts to SOAP services, Salesforce provides the WebServiceMock
interface for us to implement and use.
The interface includes a single method, doInvoke
, which takes in a list of parameters that allow you to perform logic within the implementation to return the correct data. Let us create a sample mock for us to use that returns a response containing the converted temperature. Here, you can see the code for a basic implementation that will return a CelsiusToFahrenheitResponse_element
instance, which is the parameter holding the response
object we can see within our generated code:
@isTest public with sharing class W3CTempConverterMock implements WebServiceMock { public void doInvoke( ...