unit-testingvisual-studio-2012.net-4.0microsoft-fakesshim

UnitTestIsolationException: Debug Unit Test at ShimsContext.Create


When I am trying to debug a Unit test, I receive the following exception message:

UnitTestIsolation instrumentation failed to initialize. Please restart Visual Studio and rerun this test

With this stack trace:

at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider() at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext() at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create() at Sample.Business.Tester.ProcessorManagerTest.Test_first_run_ever() in d:\Folder1\Sample.Business.Tester\ProcessorManagerTest.cs:line 62

The code is:

var prc = new ProcessorManager(ProcessRepository,ProcessStatusRepository);
using (ShimsContext.Create())
{
    ShimDateTime.NowGet = () => new DateTime(2015, 10, 1);
    prc.Run();
}

The exception is thrown at ShimsContext.Create().

I have reviewed the Visual Studio 2012 fakes UnitTestIsolation instrumentation failed to initialize, and tried all the steps there but doesn't work for me. I am not using Nunit.


Solution

  • If there is a problem with your Unit testing project, related to fakes or shims, do the following:

    1. In references, remove these dlls:
      • Microsoft.QualityTools.Testing.Fakes
      • Microsoft.VisualStudio.QualityTools.UnitTestFramework
      • System.4.0.0.0.Fakes
      • mscorlib.4.0.0.0.Fakes
    2. Also in "Fakes" folder, remove these files:
      • mscorlib.fakes
      • System.fakes
    3. Add the dlls:
      • Microsoft.QualityTools.Testing.Fakes
      • Microsoft.VisualStudio.QualityTools.UnitTestFramework

    from the following source path: C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\PublicAssemblies

    1. Right click on the "System.dll" and choose in the contextual menu "Add fake assembly".
    2. Clean project.
    3. Build project.