Welcome to MSDN Blogs Sign in | Join | Help

SPG Continuous Integration builds not run on instance of SharePoint

Our Continuous Integration builds are run on a build server that has the necessary SharePoint assemblies, but with no installed instance of SharePoint.

Licensing issues aside, this causes an interesting problem when unit tests are developed on dev boxes that have SharePoint installed. Several services found in the SPG Partner Portal application access SPFarm.Local. Developers often fail to mock out this dependency in unit tests as this property is always available on boxes that have SharePoint installed. These unit tests ran fine on dev boxes, but fail to run on the build server and it took some time to figure out why.

As part of good unit testing, remember to mock out any of your code’s dependent objects that could potentially cause problems with your tests. Here is a simple example of how we use Typemock Isolator to mock the SPFarm.Local property.

 

SPFarm fakeSPFarm = Isolate.Fake.Instance<SPFarm>();
Isolate.WhenCalled(()=>SPFarm.Local).WillReturn(fakeSPFarm);

//Arrange
//Act
//Assert
Published Wednesday, June 24, 2009 7:53 PM by fcheung

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SPG Continuous Integration builds not run on instance of SharePoint

Wednesday, June 24, 2009 4:43 PM by Mr. Hericus

Interesting point.  Do you think there would be a way to scan for these types of errors in the unit tests, and automatically replace them with the mock'd out interface.

That way it wouldn't be something that would cause the builds or tests to fail, it would just be automatically handled during the build process.

# re: SPG Continuous Integration builds not run on instance of SharePoint

Friday, July 17, 2009 5:35 PM by fcheung

Hmmm... I'd be worried about the "automatic" behaviour causing strange side effects. Especially for developers new to the team who aren't aware of this functionality.

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
 
Page view tracker