开发者

Unit Testing and SharePoint Development

I am interested in writing unit tests for the SharePoint development work I am doing. 开发者_JAVA技巧 Can anyone suggest practical approachs to implementing unit tests in MOSS?

Note that any third party tools have to be free (but not necessarily open-source); the company I work for will not pay for additional tooling. In particular, any alternatives to the Typemock Isolator for SharePoint would be appreciated.

Thanks, MagicAndi.


A controversial alternative for you - don't use mocks!

Instead do integration testing because really as soon as you are using the SharePoint OM that is what you are doing.

Put as much of your logic in library assemblies that can run from outside a request Context (overload constructor to pass in either HttpContext or SPWeb).

Setup a server/site (VM preferably so you can rollback and make new instances easily) just for unit tests and run against this. (VMWare Server is free)

If you running continuous build you should be able to set it to run automagically and report results. Alternatively some batch file magic with the open source nUnit or your tool of choice to run the tests as soon as a new .dll is copied over on a PostBuild step.

The disadvantages

  • You've got a bit of work setting up data for your tests (though is it much more than getting mocks working?)

  • Not everything can be tested like this

  • May take a little longer to run, but if running as part of a continuous build is that a problem?

  • More discipline needed in a team to avoid stepping on other peoples toes.

The advantages

  • Your testing against the real SharePoint OM with all its baffling inconsistencies and special cases (if you were being unkind you may call them bugs ;)

  • Who knows what parts of the OM behaviour could subtly change when new service packs / cumulative updates come along, this should help catch any breaking changes.

  • When SharePoint 2010 comes along you will be able to run your tests against both 2007 and 2010, see what changed, make sure your library works against both versions (if appropriate to your project)

The trade-offs for all projects are different, but for my projects I prefer the security of knowing I am testing against the real thing - call me old fashioned if you will!


To my knowledge, there are none except the Typemock Isolator for SharePoint you mentioned. Unit testing SHarePoint is notoriously diffcult.


Andrew Woodward is a big TDD and SharePoint fan - check out his site here: http://www.21apps.com/agile/unit-testing-sharepoint-getting-into-the-object-model/


I've recorded a web cast on SharePoint Unit Testing. It is also covered on SharePointDevWiki.com too.


It seems that JustMock from Telerik also can be used. It can also mock sealed classes, statics and so on.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜