Unit Testing and SharePoint Development
Asked Answered
D

5

5

I am interested in writing unit tests for the SharePoint development work I am doing. 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.

Downes answered 12/10, 2009 at 8:33 Comment(0)
C
5

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!

Cruikshank answered 12/10, 2009 at 10:39 Comment(1)
Ryan, an extremely interesting answer. It complements some other articles that I have read (pseale.com/blog/SharePointNotUnitTesting.aspx). +1Downes
O
2

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

Origan answered 12/10, 2009 at 10:1 Comment(0)
T
2

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/

Trial answered 12/10, 2009 at 10:4 Comment(1)
Phill, I came across the link before, but as it is such a useful one, +1Downes
Q
2

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

Quirk answered 12/10, 2009 at 12:43 Comment(0)
B
1

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

Belshazzar answered 14/5, 2010 at 10:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.