Posts Tagged ‘Unit Testing’
Monday, March 15th, 2010



One of the challenges with unit testing SharePoint projects is the need to fake the calls into SharePoint.  If you are a regular reader of my blog you will have seen examples of how I have been doing this using Typemock Isolator. 

Microsoft have their own isolation framework called moles.  A more accurate descripition would be isolation through detours and stubs.  Moles was developed to support Pex white box testing and one interesting development from within the team has been Behaviours.  Behaviours are really a way to model the thing you want to isolate for the test without needing to define every isolation point. 

Isolatation frameworks (regardless of technology) can result in brittle code, test code that is very tightly linked to the production code.   A simple change from List.GetItems() to List.Items[""] will cause the test to fail.

One of the samples provided with Pex is the modelling of SharePoint Behaviour that will make it much easier for people to be able to create robust tests with minimal or no additional isolation code needed.   Part of the work we are doing is to drive out the things that need to be modelled and reporting these to the Pex team.  It is not going to be easy to model the whole of SharePoint from day one,  however it should be possible to cover the areas most used.

This is where I would like some help.     Do you have any code that you use often,  code that you would like to unit test that takes a long time to isolate and that end up being brittle?

Please post examples here in the comments and we will try to get as much covered as possible.

Thursday, June 25th, 2009



Following on from my rant response yesterday about the more negative views from the SharePoint community my reading this morning was so much more positive.

Unit Testing Workflows

In my response to a question from Aaron Weiker I said that I would like to see much more guidance and investigation into the way we approach Unit Testing workflows in SharePoint,  so it was great to find Richard Fennell is doing a lot of work in this area.  I have been working with Typemock Isolator, CThru and SilverUnit testing recently (post coming) and was very interested to see that Richard had picked up this whilst looking for a possible solution to the challenges of Unit Testing SharePoint workflows; something I have to confess I had not even considered.

I’m looking forward to seeing where Richard gets with this and also the use of Fit/Fitness, although I’m personally not a big fan of the way tables are used to define the tests.

Integration Testing SharePoint from MSTest

Having been a bit behind with my reviews of the latest Codeplex P&P project I missed the discussion with Francis on how they found a use for Typemock Isolator to do Integration tests.

The code is really very very simple,  many will be glad to hear, and deals with the places where your code makes a call to SPContext.Current or SPFarm.Local.

The simple ideas really are the best ones.

As you can see,  a few small steps for testing but big steps for SharePoint testing and a demonstration that in general the SharePoint community is committed to improving the way solutions are developed.

Tuesday, May 19th, 2009



One of my favourite tools Typemock has just been released in a fantastic ASP.Net bundle and have once again offered this up to the blogging community to get for free.

Unit Testing ASP.NET? ASP.NET unit testing has never been this easy.
Typemock is launching a new product for ASP.NET developers – the ASP.NET Bundle – and for the launch will be giving out FREE licenses to bloggers and their readers.
The ASP.NET Bundle is the ultimate ASP.NET unit testing solution, and offers both Typemock Isolator, a unit test tool and Ivonna, the Isolator add-on for ASP.NET unit testing, for a bargain price.
Typemock Isolator is a leading .NET unit testing tool (C# and VB.NET) for many ‘hard to test’ technologies such as SharePoint, ASP.NET, MVC, WCF, WPF, Silverlight and more. Note that for unit testing Silverlight there is an open source Isolator add-on called SilverUnit.
The first 60 bloggers who will blog this text in their blog and tell us about it, will get a Free Isolator ASP.NET Bundle license (Typemock Isolator + Ivonna). If you post this in an ASP.NET dedicated blog, you’ll get a license automatically (even if more than 60 submit) during the first week of this announcement.
Also 8 bloggers will get an additional 2 licenses (each) to give away to their readers / friends.
Go ahead, click the following link for more information on how to get your free license.

I’ve not had the chance to try out the Ivonna or SilverUnit add-ons to the framework yet, but will be looking at these in the near future and they can help you test more of your SharePoint solutions.

Thursday, April 23rd, 2009



Great to see that more people are publishing their experiences with unit testing SharePoint.   Here are some of examples I have found that are really worth looking at:

Richard Fennell – Testing SharePoint Workflows using TypeMock Isolator (part 1, part 2 and part 3) – Richard is also going to be talking at a few NextGen meetings on the subject.

SharePoint Dev Wiki is really starting to get some good content not just on unit testing but on the whole development field.

Jeremy Thake (creator of SharePoint Dev Wiki) did a great usergroup meeting web cast on SharePoint Development with Unit Testing

I’ve previously mentioned the Patterns and Practices work and they have started to do some great Channel 9 videos which really do make this so much more accessible.  Brilliant Job!

If you have any links or posts on the subject please share by adding a link in the comments, and if you’ve done something new and exciting help the SharePoint Dev Wiki by posting details.

Looks like my predictions are starting to come true,  people really are doing SharePoint development better :)