Rickard Nilsson is a software architect, developer, craftsman, agile enthusiast, and father of three... More
Rickard blogs about crafting software using .NET tooling and solid, development practices.
Moles is a new framework from Microsoft Research for isolating objects in unit tests. With the framework you create test stubs by using delegates and you can route any .NET method you want, including non-virtual and static methods in sealed classes. In addition, the framework is free, making it a major competitor to TypeMock Isolator that has been alone on this functionality for a long time.
Moles automatically generates stubs for all classes in one assembly. Here is an example of how easy it is to change the behavior of the static DateTime.Now property:
// change the value of DateTime.Now MDateTime.NowGet = () => new DateTime(2000,1,1); if (DateTime.Now == new DateTime(2000,1,1)) throw new Y2KBugException();
Mole’s strength to fake and reroute static methods and the like makes it a very powerful tool for isolating and unit testing code developed for SharePoint. Microsoft Research has a whitepaper that describes how to get started:
Unit Testing SharePoint with Microsoft Foundation Pex and Moles
Here is a video that introduces Moles:
Related posts
Comments
April 13. 2010 18:33
Pingback from topsy.com Twitter Trackbacks for Moles Isolation Framework from Microsoft to be compared with TypeMock Isolator [rickardnilsson.net] on Topsy.com
topsy.com