3

I am attempting to use Microsoft Fakes in VS 2015 Enterprise. I have been unable to get any of the tests to even run.

I do not have a testsettings or runsettings file.

Simple test project has references to:

Microsoft.QualityTools.Testing.Fakes
Microsoft.VisualStudio.QualityTools.UnitTestFramework

Single class of 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 happens 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 have tried various solutions such as Unable to Run Unit Tests that uses Microsoft Fakes - Exception in ShimsContext.Create(), but no luck.

EDIT: I tried running this from the console, but didn't include the output. Here is the output, it fails 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 to turn off the specific version for the Fakes reference.

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>
Dish
  • 127
  • 1
  • 10
  • Are you using MSTest.exe to run the unit tests? If so, tests using fakes need to use VStest.console.exe – Foxocube May 24 '17 at 10:47
  • @CyberJacob It appears to be using MSTest because I haven't been able to change it to use VSTest. Is is possible to set VS to use VSTest? Or do we have to run them from the console? Note: I have edited the post to show that it still fails from the command line. – Dish May 24 '17 at 13:34
  • Check in the Microsoft Fakes dll reference in the test project if `SpecificVersion` is set to true. Should be false. – zaitsman May 26 '17 at 09:29
  • @zaitsman I have edited my post to reflect trying this, let me know if I tried the right thing. It appears to not have worked. I based my attempt off this answer: https://stackoverflow.com/a/24022135/793028 – Dish May 26 '17 at 17:00
  • It appears that no cor variables exist... I guess I assumed that VS would handle all of that upon installation. Any ideas on how to set these? So far, the only pages I have found reference "set the variable to your desired profile" but I cannot find a "this is the default VS 2015 VSTest Profiler Settings" – Dish May 26 '17 at 19:36
  • Google "microsoft fakes cor_profiler". Lots of hits, they all say the same thing. – Hans Passant May 26 '17 at 23:10

0 Answers0