8

刚刚安装了 vs 2012 更新 2 ( http://www.microsoft.com/en-us/download/details.aspx?id=36833 ) 所以我可以使用 vs fakes/shims 来测试一些难以测试的代码。当我创建假程序集并且所有引用都按预期添加到单元测试项目中时,一切都编译得很好。但是在任何测试中运行以下代码......

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

引发以下异常...

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

堆栈跟踪的完全异常...

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()

一些笔记...

  • 我正在使用 Visual Studio 2012 高级版
  • 解决方案中的所有项目都针对 .net 4.0
  • 我正在使用 nunit 作为测试框架
  • 尝试通过 testdriven.net 插件和 nunit gui 运行测试,但同样的错误。
  • 尝试定位 .net 4.5 并得到相同的错误
  • 我没有使用 Typemock 或 Ncrunch 并且它们没有安装
  • 我正在使用起订量,但将其从 th 中删除
  • 它与特定测试无关,我已经验证它在不同的测试文件和另一个解决方案中都失败了。
4

3 回答 3

9

马修是对的。您必须使用 vs 测试运行器。

- 必须通过扩展管理器安装 NUnit 测试适配器 0.94,它允许 vs 测试运行器运行 nunit。

- 必须使用 vs 测试资源管理器窗口来运行测试。

看起来测试运行将运行测试包装在上下文中以使假货魔术发生。

于 2013-03-25T05:17:50.623 回答
2

此外,如果您想从 CI 服务器运行测试,则需要从控制台执行 VS Test Runner,并指定您要使用 nUnit 发现器扩展。

该命令将是这样的:

{ProgramFiles}\Microsoft Visual Studio\11.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow>vstest.console.exe /inIsolation /UseVsixExtensions:true {testsPath}
于 2013-07-18T10:11:30.240 回答
0

在调试下重置您的异常设置:

菜单调试 -> 例外 -> 全部重置。

一旦我通过取消选中调试模式来更改异常设置:

“当此异常类型为用户未处理时中断”

这导致了这个问题。

于 2014-07-15T16:03:31.000 回答