Salesforce integration testing – WebServiceMock interface
Salesforce integration testing: Generating web service class and how to use those web service classes was explained in my previous post. Here I am going to explain about how to write test class for web services class generated WSDL2Apex.
Every Salesforce developer know about importance of test classes. At least 75% code coverage is required to deploy code to production. Test coverage includes classes generated by WSDL2Apex.
As a Salesforce developer, to write test classes for web service you should spend some time as test methods do not support web service callouts. Apex provides inbuild interface “WebServiceMock” and the “Test.setMock” method. Developers can use this interface to receive fake response in a test method.
What is WebServiceMock interface?
WebServiceMock interface enables sending fake response when testing web service callouts of a class auto-generated from WSDL.
doInvoke is the method of this interface.
doInvoke(stub, soapRequest, responseMap, endpoint, soapAction, requestName, responseNameSpace, responseName, responseType)
The implementation of this method is called by the Apex Runtime to send a fake response when a service callout is made after Test.setMock has been called.
You can refer below Salesforce documentation to know more about this interface.