UnitTestIsolationException:而在发行/调试模式下运行测试垫片抛出异常 [英] UnitTestIsolationException: Throws Exception while running Shims test in Release/Debug mode

查看:546
本文介绍了UnitTestIsolationException:而在发行/调试模式下运行测试垫片抛出异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行使用Microsoft垫片这个单元测试,但它抛出我 Shims.Context.Create(例外); 方法。



环境: VS 2012,Win2K8 R2

 命名空间MyShimsUnitTest 
{
[TestClass中]
公共类MyUnitTest
{
[TestMethod的]
公共无效GetCurrentYear()
{使用
(Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create())
{
//一些逻辑...
}
}

}
}

详细的异常:

 结果消息:
Microsoft.QualityTools.Testing:MyShimsUnitTest.MyUnitTest.GetCurrentYear抛出异常
试验方法。 Fakes.UnitTestIsolation.UnitTestIsolationException:UnitTestIsolation仪器初始化失败。请重新启动Visual Studio并重新运行该测试
结果堆栈跟踪:
在Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()在Microsoft.QualityTools.Testing.Fakes.Shims
。 ShimRuntime.CreateContext()
在Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
在MyShimsUnitTest.MyUnitTest.GetCurrentYear()


解决方案

垫片需要得到的IntelliTrace事件探查器进行运行时检测。测试运行器负责设置为CLR所需要的环境变量来加载探查以及提供的类型列表必须探查仪器垫片。当ShimRuntime无法找到并连接到智能跟踪分析器,它预计将被CLR已加载的UnitTestIsolationException被抛出。



由于锦旭前面提到的,当测试是由不执行所需的初始化探查一个亚军执行发生此问题。测试资源管理器和vstest.console.exe两个这样的选手即与Visual Studio 2012年出货在这个时候,在传统模式,当你有这恰好运行测试时Visual Studio的测试运行不执行所需的探查仪器选择.TESTSETTINGS文件为您的跑步或.RUNSETTINGS文件部队传统模式。



您可能能够使用支持探查仪器所要求的第三方测试运行垫片。


I am trying to run this unit test using Microsoft Shims, but it throws me exception in Shims.Context.Create(); method.

Environment: VS 2012, Win2K8 R2

namespace MyShimsUnitTest
{
    [TestClass]
    public class MyUnitTest
    {
        [TestMethod]
        public void GetCurrentYear()
        {
            using (Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create())
            {
                // Some Logic...
            }
        }

    }
}

Detailed Exception:

Result Message: 
Test method MyShimsUnitTest.MyUnitTest.GetCurrentYear threw exception: 
Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationException: UnitTestIsolation instrumentation failed to initialize. Please restart Visual Studio and rerun this test
Result StackTrace:  
at Microsoft.QualityTools.Testing.Fakes.UnitTestIsolation.UnitTestIsolationRuntime.InitializeUnitTestIsolationInstrumentationProvider()
   at Microsoft.QualityTools.Testing.Fakes.Shims.ShimRuntime.CreateContext()
   at Microsoft.QualityTools.Testing.Fakes.ShimsContext.Create()
   at MyShimsUnitTest.MyUnitTest.GetCurrentYear()

解决方案

Shims require runtime instrumentation performed by the IntelliTrace profiler. The test runner is responsible for setting up the environment variables required for CLR to load the profiler as well as providing the list of types the profiler must instrument for Shims. The UnitTestIsolationException is thrown when the ShimRuntime is unable to locate and attach to the IntelliTrace profiler, which it expects to be already loaded by the CLR.

As Jin-Wook mentioned earlier, this problem occurs when the test is executed by a runner that does not perform the required profiler initialization. Test Explorer and the vstest.console.exe are two such runners that ship with Visual Studio 2012. At this time, the Visual Studio test runners do not perform the required profiler instrumentation when running tests in "legacy" mode, which happens when you have a .TESTSETTINGS file selected for your run or a .RUNSETTINGS file that forces legacy mode.

You may be able to use third-party test runners that support profiler instrumentation required by Shims.

这篇关于UnitTestIsolationException:而在发行/调试模式下运行测试垫片抛出异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆