I am trying to use Microsoft Fakes in VS 2015 Enterprise. I was not even able to run any of the tests.
I do not have a settings file or settings file.
A simple test project has links to:
Microsoft.QualityTools.Testing.Fakes
Microsoft.VisualStudio.QualityTools.UnitTestFramework
One class from the following:
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Microsoft.QualityTools.Testing.Fakes;
namespace UnitTestProjectfortemp1
{
[TestClass]
public class UnitTest1
{
[TestMethod]
public void TestMethod1()
{
using (ShimsContext.Create()) { }
}
[TestMethod]
public void TestMethod2()
{
using (ShimsContext.Create()) { Console.Write("test"); }
}
}
}
The error that occurs for both tests:
Test Name: TestMethod1
Test FullName: UnitTestProjectfortemp1.UnitTest1.TestMethod1
Test Source: C:\UnitTestProject1\UnitTestProject1\UnitTest1.cs : line 21
Test Outcome: Failed
Test Duration: 0:00:00.0131326
Result StackTrace:
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.ResolveProfilerPath()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
at UnitTestProjectfortemp1.UnitTest1.TestMethod1() in C:\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 23
Result Message:
Test method UnitTestProjectfortemp1.UnitTest1.TestMethod1 threw exception:
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.
I tried various solutions, such as Failed to run unit tests that use Microsoft Fakes - Exception in ShimsContext.Create () , but no luck.
EDIT: I tried to run this from the console, but didn't turn on the output. Here is the result, it does not work with VSTest
C:\UnitTestProject1\UnitTestProject1>vstest.console.exe bin\Debug\UnitTestProject1.dll
Microsoft (R) Test Execution Command Line Tool Version 14.0.25420.1
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
Failed TestMethod1
Error Message:
Test method UnitTestProjectfortemp1.UnitTest1.TestMethod1 threw exception:
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.
Stack Trace:
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.ResolveProfilerPath()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
at UnitTestProjectfortemp1.UnitTest1.TestMethod1() in C:\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 12
Failed TestMethod2
Error Message:
Test method UnitTestProjectfortemp1.UnitTest1.TestMethod2 threw exception:
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: Failed to resolve profiler path from COR_PROFILER_PATH and COR_PROFILER environment variables.
Stack Trace:
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.ResolveProfilerPath()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.IntelliTraceInstrumentationProvider.Initialize()
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
at UnitTestProjectfortemp1.UnitTest1.TestMethod2() in C:\UnitTestProject1\UnitTestProject1\UnitTest1.cs:line 19
Total tests: 2. Passed: 0. Failed: 2. Skipped: 0.
Test Run Failed.
Test execution time: 0.2654 Seconds
Edit 2: Based on zaitsman's comment below, I tried disabling the specific version for the Fakes link.
Before it was:
<ItemGroup>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL"/>
<Reference Include="System" />
</ItemGroup>
After:
<ItemGroup>
<Reference Include="Microsoft.QualityTools.Testing.Fakes, Version=12.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
</Reference>
<Reference Include="System" />
</ItemGroup>