【发布时间】:2013-07-18 07:18:25
【问题描述】:
环境
- Visual Studio 2012 高级更新 3
- Team Foundation Server 2012 更新 3
- 编辑:.NET Framework 4
- 默认模板 (DefaultTemplate.11.1.xaml)
- Visual Studio 测试运行程序
- 目标平台:X86
- Visual Studio 测试运行程序
问题
我有 2 个单元测试程序集:
- 扩展测试
- 用户测试
两者都使用 Microsoft Fakes Framework(使用 Stubs 和 Shims)。
在本地运行单元测试很好(在 4 台不同的机器上测试,甚至在构建服务器上安装的 Visual Studio 上测试),但是如果我们使用构建代理构建,一些单元测试会失败并显示例外,例如:
Unable to create instance of class UserTests.ClientUserTest. Error: System.TypeLoadException: Could not load type 'WorldDirect.CCM.Shared.Backend.SmartClassic.Fakes.StubClient' from assembly 'WorldDirect.Smart.Backend.Fakes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
或相同的垫片:
Test method ExtensionTests.ExtensionTests.UpdateExtensionValidate_NoGrnp_ChecksIpPbxDependencies threw exception: System.TypeLoadExceptio: Could not load type 'WorldDirect.CCM.Shared.Backend.SmartClassic.Fakes.ShimIpPbxRemoteDestination' from assembly 'WorldDirect.Smart.Backend.Fakes, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null'.
有趣的是,他们偶尔会失败,我试图弥补一些统计数据:
# | Outcome | Comment
19 | 64/64 passed | only 'UserTests'-UnitTests run, 'ExtensionTests' inactive
20 | 37/64 passed | same source code as #19
21 | 64/64 passed | same source code as #19
22 | 64/66 passed | all 'UserTests' run as well as 2 'ExtensionTests', others still inactive; the 2 ExtensionTests failed with ShimIpPbxRemoteDestination-TypeLoadException
23 | 38/65 passed | same source code as #22, notice NOTHING has changed, however 1 unit test was not even run in 'ExtensionTests'; however the second succeeds; all unit tests in 'UserTests' using MS Fakes fail with a StubClient-TypeLoadException
24 | 38/65 passed | same source code as #22
new day - no more luck :-(
1 | 37/64 passed | uncommented the 2 'ExtensionTests', so same code as #19
2 | 37/64 passed | so same code as #1
3 | 64/64 passed | so same code as #1; suddenly they all work again
请注意,除了提到的更改之外,没有人更改源代码。
所有构建都是使用详细的日志级别进行的;
垫片诊断 =“真”;
只有明确需要的垫片/存根包含在 .fakes 文件中(否则 MSBUILD 使用退出代码 1 失败)。
这一切对我来说似乎很神奇,可能有人已经遇到过同样的问题或者有人有提示。
提前致谢
【问题讨论】:
-
请在connect.Microsoft.com/VisualStudio 提交一个小项目的错误,该项目重现该问题。
-
谢谢。我们今天开始研究它。
-
Visual Studio 2013 中仍然存在同样的问题,但是为所有测试项目使用相同的 .fakes 文件的解决方法可以解决这个问题。
标签: visual-studio-2012 build-process microsoft-fakes