4

I was wondering if there are any existing solutions for unit-testing Windows Workflow Foundation workflows that run in SharePoint context.

Unfortunately, SharePoint libraries were not designed with possibility of testing or mocking in mind.
Such workflows are usually tightly bound to SharePoint classes that require SharePoint instance to be installed and running, which is absolutely ineffective for testing.

Following is a list of challenges I faced while trying to unit-test an existing workflow:

  • Workflows make calls to static SharePoint objects;
  • Some EventArgs classes that are necessary for mocking are internal to SharePoint assembly;
  • Workflows may use special SharePoint Workflow Activities which in turn make calls to SharePoint;
  • There is no convenient API for starting a workflow in SharePoint context and monitoring its state.

I solved these problems for a certain workflow I had to test using Microsoft Moles and probably will someday release my solution as open source.
Meanwhile, I'm wondering if any of you ever unit-tested SharePoint workflows. If so, I'd like to hear about your solutions to these (and probably some other) problems. I'd also like to know if my library, if I release it, would be of interest to you.

Thanks.

Dan Abramov
  • 241,321
  • 75
  • 389
  • 492

1 Answers1

2

Unit Testing Workflows? In general unit-testing Sharepoint is rather hard.

I have used two frameworks together with Sharepoint:

Neither of these frameworks is able to test Microsoft Sharepoint Activities or in particular, Workflows made with SHarepoint Designer as those are sealed and you should consider them "working" anyways - Microsoft made them, they're perfect! :-)

Your library is certainly of great interest as there are not many people trying to unit test Sharepoint due to Sharepoints nature in my eyes: You use lot of built in functionality and just customize and and probably add to that functionality - basically you only want to test/unit test your own code.

Sorry, can't give you specifics on the problems I faced - Typemock was definitely more powerful to use as it is a lot older and mature - Pex&Moles is fun though (I found the tutorial for Sharepoint rather nice: Unit Testing SharePoint Foundation with Microsoft Pex and Mole.

Dennis G
  • 20,757
  • 17
  • 90
  • 129
  • For SharePoint activities, I went for replacing `ISharePointService` and `ITaskService` implementations with my own and registering them in code. – Dan Abramov Feb 23 '11 at 18:18
  • Nice, but oh-so-complicated ;-) There's a lot of stuff you have to mock in Sharepoint... – Dennis G Feb 23 '11 at 18:22