Unit Testing SharePoint

Doing automated unit tests in SharePoint isn’t easy.

As with all libraries that haven’t been designed with unit testing in mind, SharePoint object model doesn’t expose its dependencies:  it connects to a Content Database given the context creating it and there are no ways to redirect it to some stub implementations.

That is unless you can override method invocations.  This is what Visual Studio fakes do.

Fakes allow a developer to create a stub out of a real object by rerouting calls to properties or methods.

For SharePoint, Microsoft just released SharePoint Emulators, a system of Fakes based shims implementing the basic behaviours of the SharePoint 2010 server object model.

Developers can now use those shims to write unit tests on code using the SharePoint 2010 server object model.


Leave a comment