Thursday, April 21, 2011

Salesforce Apex Test class and callouts

The Test.isRunningTest() method is a useful method to bypass web service callouts when running automated test cases that would otherwise fail.

For example, in any wsdl2apex generated classes find the WebServiceCallout.invoke() method calls and then wrap them in an test for Test.isRunningTest(). If the test is false the code can still call invoke as generated. Otherwise the code can simulate the web service response, allowing the test cases to complete.

No comments:

Post a Comment