Salesforce Tip: HTTP Callouts test with HttpCalloutMock
March 25, 2013 /
Posted in Salesforce Corner, Tips and Tricks
In one of the previous post, I shared a workaround to simulate the HTTP request response in Test class. The method is not elegant but at least it works for me 😀
In Salesforce Winter’13 release, Salesforce has introduced a new Apex class, HttpCalloutMock where it allows you to create a proper test method for HTTP callouts. Below are the high level steps that you need to do to simulate the HTTP callout in your test class:
- create a class that implements HttpCalloutMock with a sample response
- initialize the HttpCalloutMock class in your test class by using Test.setMock() method
For more details, please see the official documentation.