Unit testing is very difficult with SharePoint. Much SharePoint development is involved with the user interface, which is notoriously difficult to unit test. But an even worse problem is that the SharePoint object model API is large and complex, and interactions with SharePoint objects often comprise the majority of the coding in a SharePoint development project.

FakePoint gives you an alternative to mocking that allows you to replace the SharePoint API with a set of fake classes. Rather than setting up a response for each API call prior to running the test, an entire fake SharePoint site is created. Ones this fake site is set up, any number of tests can be run against it. It also removes the need to predict what the API response would be to a particular call in order to set up the response conditions.

In the following sections we will discuss the motivation and challenges of SharePoint unit testing, present some brief notes on installation and getting FakePoint running, and then look at the specifics of building a test for a web part before considering how to use FakePoint to emulate the SharePoint API in unit tests. A final section looks at the recommended approach for the fairly common situation of needing to build unit tests for SharePoint code that has already been written.


Last edited Jan 12, 2010 at 11:09 AM by flosim, version 10


No comments yet.