Microsoft Moles

Moles vs Fakes: The Differences

If you’re a fan of the Microsoft Moles framework you’ve probably heard that it’s being included in Visual Studio 2012 as Microsoft Fakes.  As I was preparing my talk covering this isolation framework I noted some of the key differences between the two.  Rather than going back and updating my original post regarding Moles (much of which is still applicable even with terminology changes) I thought I’d list those differences here.  So without further ado:

  • Assembly generation is driven by a .fakes file rather than a .moles file
  • Isolation types are placed in a .Fakes assembly and .Fakes namespace
  • Shim types replace Mole types
  • Stub types are prefixed with “Stub”
  • Shim types are prefixed with “Shim”
  • ShimsContext replaces HostTypeAttribute for enabling profiling
  • Profiling occurs in the IntelliTrace profiler rather than the Moles profiler
  • Fakes allows shims for static constructors whereas Moles allowed erasing static constructors through an assembly attribute
  • Fakes does not provide any support for finalizers whereas Moles allowed erasing finalizers through an assembly attribute
  • Moles allowed controlling whether the profiler would run as a 32-bit or 64-bit process but this is now handled entirely by the IntelliTrace profiler
  • The “classes” filter attribute was removed.
  • Fakes supports isolating auto-implemented properties
  • Fakes play much nicer with testing frameworks other than MSTest when run through Visual Studio
Advertisements

Speaking in Fort Wayne

Ok, this should be the last post about speaking engagements for a while ;)  I have something else in the works that’s going to take a lot of my attention for some time (more on that on Friday). 

I’m pleased to announce that I’ll be returning to Fort Wayne in June to talk about the Microsoft Fakes framework (formerly the Moles framework).  In this talk I’ll introduce the Fakes framework, discuss the use cases for the different isolation techniques, and show how to take advantage of them in your unit tests.

The meeting will be held on Tuesday, June 12 at the Northeast Indiana Innovation Center.  Pizza and drinks will be available at 6:00 with the presentation starting at 6:30.  For more information please check the NUFW site.

Going Underground: Microsoft Moles

3/27/2012 Update: According to the Moles page, the Moles framework has been integrated into Visual Studio 11 as the Fakes framework and Moles is no longer under active development.   After a quick review of the changes it appears that most of this guide still applies but there are a few changes to be aware of:

  • Mole types are now referred to as Shim types
  • The configuration file now has a .fakes extension
  • The generated types are now placed in a .Fakes namespace (i.e.: System.Fakes)

6/25/2012 Update: In preparation for my Faking It talk covering the Fakes framework I compiled a list of the notable differences between Moles and Fakes. There are quite a few more than I listed above so if you’re using this post as an introduction to either framework you’ll probably want to look them over.

Despite having been around for several years I hadn’t heard about Microsoft’s Moles framework until a few months ago when one of my teammates mentioned it during the 2011 Indy GiveCamp. I was interested in learning more about it at the time but given how we were running on caffeine I’m not surprised I forgot about it until he mentioned it again a few weeks ago. This time I was much more alert and started reading about it almost immediately. After seeing what Moles offered and not finding much in the way of resources for it on the Web I knew I needed to spread the word.

(more…)