Mocking is the practice of substituting the standard implementation of classes and methods with stub methods that return a fixed value. Other development stacks have rich and robust mocking capabilities built in. Salesforce1, on the other hand, is slowly expanding into the mocking world. In fact, there's only one built-in mock interface for you to stub. Despite the lack of a robust mocking library built into the platform, the capabilities of the existing mock interface make unit testing HTTP callouts a breeze. Additionally, there are other, third-party, mocking libraries that work with the Salesforce1 platform. Libraries, such as FFLib_ApexMocks
, found at https://github.com/financialforcedev/fflib-apex-mocks, allow you to stub custom objects and methods so long as you have written your class to implant an interface.
Let's take a deeper look at the HTTPCalloutMock
interface. Like most interface implanting classes, there are required methods for you to implement. In the case of HTTPCalloutMock...