我正在尝试在 VS 2015 Enterprise 中使用 Microsoft Fakes。我什至无法运行任何测试。
我没有 testsettings 或 runsettings 文件。
简单的测试项目参考:
Microsoft.QualityTools.Testing.Fakes
Microsoft.VisualStudio.QualityTools.UnitTestFramework
以下单类:
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"); }
}
}
}
两个测试发生的错误:
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.
我尝试过各种解决方案,例如无法运行使用 Microsoft Fakes 的单元测试 - ShimsContext.Create() 中出现异常 https://stackoverflow.com/questions/36464676/unable-to-run-unit-tests-that-uses-microsoft-fakes-exception-in-shimscontext-c,但没有运气。
编辑:我尝试从控制台运行它,但不包括输出。这是输出,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
编辑2:
根据下面 zaitsman 的评论,我尝试关闭 Fakes 参考的特定版本。
之前是:
<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>