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


    1. Thanks, Al.

      I had intended to put a note about that but found some conflicting information about which version it was going to be available in and forgot altogether. It’s unfortunate that they’ve restricted it to Ultimate but I guess I shouldn’t really be surprised either.

  1. Moled tests can be executed in isolated environment as “moles.runner.exe nunit-console.exe [nunit args]”, but can’t find how combine Fakes and nunit?

    1. I haven’t used Fakes in some time since I’ve changed jobs since I wrote this but if memory serves me correctly Fakes replaces the HostTypeAttribute with the ShimsContext. Under Moles, using HostTypeAttribute caused the runner to use the Moles profiler whereas ShimsContext uses the IntelliTrace provider.

      I honestly don’t remember if I ever tried running my tests with faked classes outside of the Visual Studio test runner but I do remember them running fine with the NUnit adapter extension.

      1. I tried nunit adapter too. But in our company we need run faked tests isolated on integration server (Jenkins CI)

Comments are closed.