Showing posts with label Fakes. Show all posts
Showing posts with label Fakes. Show all posts

Tuesday, January 27, 2015

Microsoft Fakes for all Visual Studio editions

If you have read about or heard about the Microsoft Fakes framework, you may know that it is the successor to Microsoft Pex and Moles.

Microsoft Pex and Moles was originally made freely available as a download from the Microsoft Research site.  Unfortunately, however, Microsoft Fakes was only originally included with Microsoft Visual Studio Ultimate edition.  Later on, Microsoft made a concession and included it also with Visual Studio Premium edition and above.

For most development teams that are Microsoft Partners, being restricted to Visual Studio Premium edition or above is usually OK.  However, the big problem with this restriction is that many companies are not Microsoft partners or are instead Microsoft customers which leverage Microsoft tooling to develop their own internal IT solutions.  In Offshore scenarios, this problem is even greater since very few Offshore development companies have access to Visual Studio Premium edition.  Many Offshore development companies are running on thin budgets and only have access to Visual Studio Professional edition.  Therefore, incorporating a framework such as Microsoft Fakes in a distributed development team becomes nearly impossible.

If you believe that Microsoft should make the Microsoft Fakes framework freely available as it formerly did with Microsoft Pex and Moles, you can vote for this UserVoice item here:

http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/7017401-make-microsoft-fakes-free-like-pex-and-moles

Wednesday, January 21, 2015

Alternatives to Microsoft Fakes

If your development team is using an edition of Visual Studio lower than Visual Studio 2013 Premium Edition (such as Visual Studio 2013 Professional), you will not have access to using Microsoft Fakes.

Even if you have access to Visual Studio 2013 Premium Edition, you may not be happy with the way in which Microsoft Fakes works compared to Mocking frameworks such as Moq or Rhino Mocks.

Well, unfortunately, one of the limitations of most Mocking frameworks such as Moq or Rhino Mocks is that they can only Mock code that is derived from interfaces or have their methods/members marked as virtual.

If the code does not fit into either of these categories, then a framework such as Microsoft Fakes allows you to fill in those gaps where you do not have control of the code (such as 3rd party code or the underlying .NET Framework classes).

The problem with the way that Microsoft Fakes works, however, is that it requires "Fakes" to be generated from all of the code references that you need to Fake.  This process adds additional time to the overall build process and can differ from developer machine to developer machine which makes it very unappealing overall.  It also does not have the same readability constructs of most Mocking frameworks.

Well, fortunately, there are alternatives to using Microsoft Fakes:

  1. Telerik JustMock: http://www.telerik.com/products/mocking.aspx - This Mocking Framework is provided by Telerik who also provides a host of controls for the Visual Studio IDE.  It offers the same types of capabilities as are offered by Microsoft Fakes with the readability of standard Mocking frameworks and the requirement to generate "Fakes" files for all assembly references.
  2. TypeMock Isolator: http://www.typemock.com/ - TypeMock has been around for a number of years and has long been a choice for many developers that needed to work around the limitations of most other Mocking frameworks.
Both Telerik JustMock and TypeMock Isolator offer free versions of their Mocking libraries, however, the free versions have many of the same limitations as the free, open-source versions of Mocking frameworks such as Moq and Rhino Mocks making the free versions limited in their usefulness.

You can compare the editions yourself here:

JustMock Edition Comparison

http://www.telerik.com/justmock/free-mocking

TypeMock Isolator Edition Comparison

http://www.typemock.com/isolator-product-page




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, October 27, 2013

Microsoft Fakes now included with Visual Studio 2013 Premium Edition!


If you are familiar with the Fakes Framework that was previously introduced with Visual Studio 2012, you may already know that it was exclusively available to other development teams entitled to Visual Studio Ultimate Edition.
Unfortunately, those development teams that were entitled to Visual Studio Ultimate Edition were a rare and elite group indeed.
In fact, most Microsoft Partner companies/organizations are only entitled to Visual Studio Premium Edition, therefore, a mocking framework such as the Fakes Framework would be completely unavailable to potentially millions of developers.
Fortunately, with the release of Visual Studio 2013, Microsoft has changed their tune in regards to the availability of the Fakes Framework.  It is now available with even the Premium Edition of Visual Studio!  Yippee!!
Here is a feature comparison available across all of the various Visual Studio 2013 editions:
http://www.microsoft.com/visualstudio/eng/products/compare

Below is the feature comparison for Visual Studio 2012  (where Fakes was notably absent in Premium edition):

http://www.microsoft.com/visualstudio/11/en-us/products/compare


It is good to know that Microsoft is listening to the feedback from the development community and subsequently making these requested changes to their feature sets in Visual Studio.

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!