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 Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s