Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Visual Studio 2012 fakes UnitTestIsolation instrumentation failed to initialize

Just installed vs 2012 update 2 (http://www.microsoft.com/en-us/download/details.aspx?id=36833) so I can use vs fakes/shims to test some hard to test code. Everything compiles just fine when I create the fake assemblies and all references are added within the unit test project as expected. However running the following code in any test...

using (ShimsContext.Create())
{
    //Doesn't matter whats in here
}

Throws the following exception...

Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException : UnitTestIsolation instrumentation failed to initialize.  Please restart Visual Studio and rerun this test

Full exception with stack trace...

Test 'Abot.Tests.Unit.Core.HapHyperLinkParserTest.HyperLinkParserTest.GetLinks_AreaTags_ReturnsLinks' failed: Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException : UnitTestIsolation instrumentation failed to initialize. Please restart Visual Studio and rerun this test
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
Core\HyperlinkParserTest.cs(59,0): at Abot.Tests.Unit.Core.HyperLinkParserTest.GetLinks_AreaTags_ReturnsLinks()

A few notes...

  • I'm using visual studio 2012 premium
  • All projects in the solution target .net 4.0
  • I'm using nunit for the testing framework
  • Tried running tests through testdriven.net plugin and nunit gui but same error.
  • Tried targeting .net 4.5 and got the same error
  • I'm NOT using Typemock or Ncrunch and they are not installed
  • I am using Moq but removed it from the th
  • Its not tied to a specific test, i've verified it fails in different test files and in another solution as well.
like image 352
sjdirect Avatar asked Mar 25 '13 04:03

sjdirect


2 Answers

Matthew was correct. You have to use the vs test runner.

-Had to install the NUnit Test Adapter 0.94 through the extension manager which allows vs test runner to run nunit.

-Had to use the vs test explorer window to run the tests.

Looks like the test running wraps the running tests in a context to make the fakes magic happen.

like image 146
sjdirect Avatar answered Oct 21 '22 01:10

sjdirect


Also, if you want to run the tests from a CI server, you will need to execute the VS Test Runner from the console, and also specify that you want to use the nUnit discoverer extension.

The command would be something like this:

{ProgramFiles}\Microsoft Visual Studio\11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow>vstest.console.exe /inIsolation /UseVsixExtensions:true {testsPath}
like image 2
lgrosales Avatar answered Oct 21 '22 03:10

lgrosales