Interested in a
Personal Demo ?

Name* :
Please Enter your Name
Company E–Mail* :
Please Enter a Valid Email


"Holy crap, this thing is hot. In technical terms, you might call it the *bomb-diggity*. I haven’t been this stoked about a technology for quite some time..."
Travis Illig, Fiserv
Travis Illig, Fiserv
Success stories


US Toll Free
Outside US
Get your printable quote
Buy online


Unit Testing SharePoint Applications the easy way


“Typemock Isolator is a great way to open up the world of unit testing 
to SharePoint developers. Unit testing SharePoint applications is an 
important part of our soon to be released P&P SharePoint Guidance 
and Typemock Isolator is integral to our unit testing guidance.”
Ajoy Krishnamoorthy, Lead Product Planner for Patterns & Practices,Developer Division at Microsoft



How to unit test your SharePoint custom code by isolating the object model (SPSite)

The biggest problem with testing SharePoint code, is its dependency on the SharePoint object model. The following example shows how to easily unit test your custom code. Here's the method we want to test:

public List GetUrgentTasks()
    var site = new SPSite("");
    var taskList = site.OpenWeb().Lists[TASKS_LIST_NAME];
    var urgentTasks = new List();
    foreach (SPItem item in taskList.Items)
    return urgentTasks;


Here's how the test looks like:

public void GetAllTasks_ThreeItemsInTasksList_ThreeTaskItemsFound()
   // Recursive fake - complete SPSite object model is faked
   var fakeSite = Isolate.Fake.Instance();
   // Swap future instance of SPSite
   // Retrieve a fake SPList to set behavior
   var fakeTaskList = fakeSite.OpenWeb().Lists[TASKS_LIST_NAME];
   // Create a fake SPListItem
   var fakeItem = Isolate.Fake.Instance();
   // List collection shall return an array containing three fake items
   (new[] {fakeItem, fakeItem, fakeItem}); 
   // Call the method under test
   var urgentTasks = classUnderTest.GetAllTasks(); 
   Assert.AreEqual(3, urgentTasks.Count);


Learn more:

Articles how others are using Isolator to test SharePoint Code: