by Njål

Unit testing – Visual Studio 2012 Fakes in Team City

image

TeamCity only supports the MsTest testrunner for running MS Tests. This testrunner does not support the brilliant Fakes Framework.

 

 

http://msdn.microsoft.com/en-us/library/ms253138.aspx
image

 

If you run the tests with MsTest – you’ll get the legendary ShimNotSupportedException – which you can read more about here.

The Visual Studio 2012 Test Runner however supports Fakes – here’s how to make Team City use this runner instead of MsTest:

image

 

“C:Program Files (x86)Microsoft Visual Studio 11.0Common7IDECommonExtensionsMicrosoftTestWindowvstest.console.exe” /inIsolation UnitTest.dll

 

Note that this requires Visual Studio 2012 on the Build Agent machine. I know a lot of you don’t like this – so you can also just copy the files in the TestWindow folder to your Build Agent and use vstest.console.exe directly.

Another thing which is nice is that the VSTest is a lot faster than MsTest.

by Njål

Visual Studio 2012 Fakes – ShimNotSupportedException when debugging tests

 

image

When testing VS2012 Ultimate I tried to use the new Microsoft Fakes framework to mock a simple static method. Running the test went fine, but I kept getting a ShimNotSupportedException when debugging the test. 

After goggling and trying all kinds of stuff I finally managed to debug the test by following these steps:

  1. Deleted the local.testsettings file (both in VS and on disk)

  2. Deleted the <solution>.vsmdi file (both in VS and on disk)
  3. Made sure IntelliTrace had these settings (not sure if this mattered):

    image

  4. Restarted VS2012
  5. Made sure that no .testsettings file were selected here

    image

Debugging of tests now works fine!
(Running/debugging the tests from Resharper still does not work – but I can live with this.)

I tried to add a new .testsettings file (with CodeAnalysis and everything else disabled) – but this makes the ShimNotSupportedException reappear again.

Similar Fakes/ShimNotSupportedException/Debug issues have been reported to MS, so I hope they get this resolved soon.

———————————————————————————————————–

Another sad fact is that the Fakes framework is only available in the Ultimate edition of Visual Studio 2012 – which retails at over USD 13,000. This makes absolutely no sense at all. ALL developers should use unit testing as part of their tool belt – and isolating tests using a mocking framework plays a key role. Microsoft Moles could be used for free in the previous VS 2010 version – and it worked great. This is very disappointing.

Please vote for this issue here: http://visualstudio.uservoice.com/forums/121579-visual-studio/suggestions/2919309-provide-microsoft-fakes-with-all-visual-studio-edi