SharePoint Emulators Simplifies Unit Testing
Microsoft has announced the availability of Visual Studio 2012 SharePoint Emulators which provide a module of Microsoft Fakes based shims and implements the basic behaviours of the SharePoint 2010 server object model.
In order to incorporate emulators into existing tests you should wrap the relevant code in a SharePointEmulationScope, which accepts EmulationMode enum as a parameter. It is enabled by default which in turn performs run time interception of all Microsoft.SharePoint.dll calls. Moreover, the relevant code will be automatically detoured at runtime and all calls against the Microsoft.SharePoint.dll assembly will be rerouted to the SharePoint emulators.
"SharePoint Emulators rely entirely on the Microsoft Fakes framework. They consist of concrete implementations of shims. However, developers will be able to reuse the same code when there is a need to run tests against a full blown SharePoint server," says Joshua Weber, Visual Studio 2012 Program Manager.
Visual Studio 2012 SharePoint Emulators are available via a NuGet package feed and requires Microsoft SharePoint 2010 Server and Microsoft Visual Studio 2012 Ultimate.In his blog post, Jousha examines the usage of emulators and also examines the steps required to extend the emulator.
"In order to unit test a SharePoint code, you need to isolate code. However, this technique is very costly and it is in this context SharePoint emulators will come in handy," says Joshua. He also feels that running tests against emulators provide significant performance improvements and reduced maintenance of test SharePoint infrastructure.
Juergen Hoeller Jul 22, 2014