SharePoint Development with Unit Testing

"unit testing is a method of testing that verifies the individual units of source code are working properly. A unit is the smallest testable part of an application. In procedural programming a unit may be an individual program, function, procedure, etc., while in object-oriented programming, the smallest unit is a method, which may belong to a base/super class, abstract class or derived/child class"
Wikipedia - Unit Testing

 In SharePoint Development, Unit Tests are hard to build due to the large number of dependencies on SharePoint Development in general.

There are multiple approaches to introducing Unit Testing into SharePoint Development:

Pros and Cons of Unit Testing in SharePoint Development

Pros Cons
Encourages TDD development Lots of plumbing - More code and complex project structures
You know when something breaks in an intricate system Negative and Positive - how far to go with this is hard to define e.g tests for invalid urls
Communicates funcionality in team development People only test code they know works
  People tend to use it as integration test rather than discrete unit tests

Getting Started with SharePoint Unit Testing

Prerequisites

Setup

What can be tested?

SharePoint Development with Unit Testing webcast


View in Browser

The SharePoint community has currently moved toward Test Driven Development but below are some useful links regarding Unit Testing in general.

Other approaches

sporm

sporm is a CodePlex project that has appeared in Alpha as of Aug 09. It takes the approach of building an ORM across a site collection which you consume rather than the API directly.

Traditionally SharePoint projects are hard to unit test, use weak typing, and require complicated XML to query for data. Sporm (TM) is specifically designed to simplify unit testing, enable strongly typed objects, and support LINQ access to SharePoint objects.
Benefits

  • Simplifies unit testing - by hiding unmockable objects like SPWeb and SPListItem
  • Enables strongly typed code - by generating classes and properties for lists and content types
  • Eliminates the need for ugly loosly typed CAML queries - by acting as a LINQ provider to your lists

External References

Labels

unittest unittest Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

Creative Commons License
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 Unported License.