Showing posts with label Moles. Show all posts
Showing posts with label Moles. Show all posts

Thursday, November 14, 2013

Migrating from Moles to Fakes

If you have used Microsoft Moles for developing your Unit Tests with Visual Studio 2010, as many of you already know, you are out of luck when it comes to using Visual Studio 2012 or Visual Studio 2013 since Moles is no longer supported on either of these IDEs.

Instead, if you have Visual Studio 2012 Ultimate Edition or Visual Studio 2013 Premium Edition and above, you can migrate to the use of the Fakes Framework.

Of course, migration to the Fakes Framework is not an automated migration process.  In fact, the code has to be manually migrated through search and replace and a significant amount of editing.  There are a great deal of articles that provide a great deal of detail on how to migrate, but this is the "For Dummies" version if you will:


  1. Open up your solution in Visual Studio 2012/2013
  2. For all of the broken references that refer to Moles Assemblies, right-click on the original assemblies and select "Add Fakes Assembly"
  3. Remove all of the broken references to the Moles Assemblies from the References area of each Unit Test project
  4. You can also remove all of the .moles files from each of your Visual Studio projects.
  5. Now, comes the very manual and very tedious part of replacement.
    • For every using statement that includes the extension .Moles, replace it with .Fakes
    • For every assembly that begins with "M", replace it with Shim
    • For ever assembly that begins with "S", replace it with Stub
    • Remove all instances of the [HostType("Moles")] attribute from all Test Methods
    • In addition, for every use of a Shim, you will have to surround the code with a using statement: using (ShimsContext.Create()) { }
  6. Now, make sure that all of your projects in the solution compile.
  7. If you are able to successfully compile your solution, you can now proceed to run all of your Unit Tests.
  8. Verify that all of your Unit Tests pass after the migration to Fakes.



Sunday, July 29, 2012

Mocking for SharePoint

When it comes to mocking objects for SharePoint, you now have a few options available to you:

  1. Microsoft Moles
  2. TypeMock Isolator
  3. Telerik JustMock

Microsoft Moles


This free isolation framework from Microsoft was first introduced shortly after the release of Visual Studio 2010 as an add-in/extension to assist developers in creating their Unit Tests.  One of the unusual characteristics of this mocking library was its ability to mock SharePoint objects amongst other various pieces of functionality.  Unfortunately, however, this isolation library is no longer being actively developed with the release of Visual Studio 2012.  The replacement to it will be called "Fakes" and is currently targeted to only ship with Visual Studio 2012 Ultimate Edition.

TypeMock Isolator


This framework has long been known for its ability to mock SharePoint objects, however, its relatively high price tag ($799) has dissuaded many SharePoint developers looking for cheaper alternatives.  Even though TypeMock Isolator offers a licensed version of Isolator for SharePoint at a significantly cheaper price ($249/yr), it requires developers to then adopt additional mocking libraries as part of their Unit Testing Development Strategy to support the features not available in the Isolator for SharePoint mocking library.  

Telerik JustMock


Telerik JustMock is a relatively new contender in the playing field for mocking libraries for SharePoint.  JustMock also offers a free version called JustMock Lite which offers many of the same features as the licensed version that may be suitable for smaller development shops.  It is a particularly appealing alternative to TypeMock Isolator because of its much smaller price tag (currently only $399) as well as its backing from a company such as Telerik which makes an impressive suite of other tools such as Telerik RadControls and Telerik JustDecompile.  For development shops that have already been using Telerik development tools, JustMock is already bundled with the Premium and DevCraft Ultimate development suites.

Monday, June 11, 2012

Visual Studio 2012 and the death of Moles

Microsoft has recently published their edition comparison of features for Visual Studio 2012:


This is their original feature comparison for Visual Studio 2010:


As you can tell from the comparison chart, they have added a few features to the Premium edition which were not available before such as Lab Management capabilities and some of the newly added features such as PowerPoint Storyboarding.  However, on the whole, the Professional edition continues to get the short end of the stick with a very nominal set of features added to the Professional edition with the Visual Studio 2012 release vs. the prior Visual Studio 2010 release.

Most notably, the newly integrated Fakes framework for isolation testing in Unit Testing is reserved exclusively for developers with an MSDN Ultimate subscription.  With the Visual Studio 2010 release, Pex and Moles was available as an integrated add-on for MSDN Premium and Ultimate subscribers while Moles could be downloaded independently for free from the Visual Studio Gallery.

Of course, Moles is no longer being actively developed (http://research.microsoft.com/en-us/projects/moles/) thereby leaving any developers that were previously using it with Visual Studio 2010 Professional high and dry to choose another alternative mocking framework.

Did Microsoft make the right decision to bundle Fakes exclusively with Visual Studio Ultimate or should Fakes be provided with Visual Studio Professional edition as well?  Perhaps it should be provided as a free download similar to Moles?

Let Microsoft know what you think and let your voice be heard!

Tuesday, July 19, 2011

Resolving Moles Assembly Reference issues

If you are experiencing issues with Moles Assembly Reference issues when loading a Visual Studio 2010 project, you will probably have to go through the following steps in order to have Visual Studio fix up the assembly references for you so that you can actually successfully compile your project:


  1. Right click on the solution and select the menu option for "Upgrade .Moles files"  
  2. You will then get a dialog prompt asking whether or not you want to update all the .moles files in your projects.  
  3. Click on the OK button to proceed with the upgrade.
  4. Re-build the solution.
  5. If everything went well, the solution should now successfully build.
  6. If things did not go so well, you can try the solution posted here: http://samirvaidya.blogspot.com/2011/02/failed-to-generate-strong-name-key-pair.html


Friday, December 31, 2010

Upgrading to newer versions of Pex and Moles

I just recently started using Pex and Moles after reading about it on the Microsoft Visual Studio web site.  I have been searching for a Microsoft-endorsed method for creating Mock objects and it seems that Microsoft finally came to the rescue with Moles.  I had been reviewing the possible use of NMock, RhinoMocks, Moq or even TypeMock, but the documentation on the open source Mock frameworks was sparse and TypeMock was quite expensive.

If you are not already familiar with Pex and Moles, you can read more about them here:
http://research.microsoft.com/en-us/projects/pex/

You can download a combined installation of Pex and Moles through your MSDN Subscription or else Moles is available for individual download from the Visual Studio Gallery.

However, once I began using Pex and Moles for inclusion within my Unit Tests, the problem I started encountering was that there were new releases of Pex and Moles nearly every few weeks.  Therefore, each time I upgraded my installation of Pex and Moles, I would encounter problems with my builds because of the dependencies on the particular version of Moles that I incorporated into my Visual Studio Unit Tests.

Well, just by chance, I discovered the option to be able to upgrade all of my .Moles files within my solution.  Simply right-click on the solution file and select the menu option for "Upgrade .Moles files".


After using this option, I can now successfully upgrade my versions of Pex and Moles without worry!