Andrew Albert wrote a great wiki article on writing tests for your Apex code that uses callouts.  Today I ran across another post on this topic by one of the stars of our community Scott Hemmeter.

As you may know, one of the cool things I do as part of my Evangelist role here at is to write toolkits.  One toolkit that I've been working on is our TwitterForce toolkit.  This toolkit, originally written and architected by the esteemed Simon Fell, enables the use of the Twitter API from Apex.  Of course, when you write an Apex toolkit, you had better write test coverage for it so that your fellow developers can actually use it in production.  I noticed that the more features of the API that I included in the toolkit meant that I had more and more test cases to cover.  I also noticed that the toolkit's main class TwitterForce was implemented as a Virtual class with a spattering of virtual methods. 

I scratched my head as to why until I looked at Simon's TwitterForceTest class.  This class implements TwitterForce and the virtual methods from TwitterForce.  This lead me to understand a new method of testing callouts.

Visit my article Virtual Callout Testing on the developerforce wiki for details.


Get the latest Salesforce Developer blog posts and podcast episodes via Slack or RSS.

Add to Slack Subscribe to RSS