Newer Version Available
Testing Asynchronous Callouts
The following example shows how to invoke a mock asynchronous callout in a test for a Web service call that uses HTTPRequest. To simulate callouts in continuations, call these methods of the Test class: Test.setContinuationResponse() and Test.invokeContinuationMethod().
The controller class to test is listed first, followed by the test class. The controller class from Make Long-Running Callouts with Continuations is reused here.
This example shows the test class corresponding to the controller. This test class contains a test method for testing an asynchronous callout. In the test method, Test.setContinuationResponse sets a mock response, and Test.invokeContinuationMethod causes the callback method for the continuation to be executed. The test ensures that the callback method processed the mock response by verifying that the controller’s result variable is set to the expected response.