Visual Studio 2010 SP1 和带有 MSTtest 的 SharePoint 2010 单元测试

发布于 2024-10-15 00:37:25 字数 982 浏览 4 评论 0原文

有人可以澄清这篇有关 .NET Framework 3.5 的基本单元测试支持的 MSDN 文章 http://msdn.microsoft.com/en-us/library/gg442059.aspx#bkmk_basicunittesting 其中指出“以下功能使开发人员能够为面向 .NET Framework 3.5 的应用程序编写单元测试和集成测试” ,包括 SharePoint 2010 应用程序”。

我所做的测试以及我对 .Net 4.0 CLR 和 MsTest 的理解是,您可以将 .Net 3.5 程序集加载到 4.0 运行时中,这允许使用针对 4.0 的单元测试项目来对针对 3.5 框架的程序集进行单元测试框架。理论上,这应该可以使用 MsTest 4.0 对 SharePoint 项目进行单元测试。

MsTest 不做的是在真正的 64 位模式下运行。由于 SharePoint 2010 需要 64 位进程,因此您会收到“加载 C:\PublicShare\64Bit - Copy\Test64Bit\bin\x64\Debug\Test64Bit.dll 时出错:无法加载测试容器 'C:\PublicShare\64Bit - Copy\”如果您将测试项目程序集构建为 64 位程序集,则在构建测试项目程序集时,请选择“任何 CPU”。要在 64 位处理器上以 64 位模式运行测试,您必须更改“主机”选项卡中的测试设置以在 32 位进程中运行测试 错误详细信息:无法加载文件或程序集“文件:/”。 //C:\PublicShare\64Bit - Copy\Test64Bit\bin\x64\Debug\Test64Bit.dll' 或其依赖项之一尝试加载格式不正确的程序。”当您尝试针对面向 x64 框架的程序集运行单元测试时,SharePoint 对象模型必须执行此操作。

在我看来,微软的声明具有误导性、不完整或误导性。有人可以澄清一下吗?

Could someone please clarify this MSDN article regarding Basic Unit Testing Support for the .NET Framework 3.5 http://msdn.microsoft.com/en-us/library/gg442059.aspx#bkmk_basicunittesting which states "The following capabilities enable developers to write unit tests and integration tests for applications that target the .NET Framework 3.5, including SharePoint 2010 applications".

The testing I've done and my understanding of the .Net 4.0 CLR and MsTest is that you can load .Net 3.5 assemblies into the 4.0 runtime, which allows for unit testing assemblies that target the 3.5 framework with a unit test project that targets 4.0 framework. This should in theory make it possible to unit test SharePoint project with MsTest 4.0.

What MsTest does not do is run in a true 64 bit mode. Since SharePoint 2010 requires a 64 bit process you get "Error loading C:\PublicShare\64Bit - Copy\Test64Bit\bin\x64\Debug\Test64Bit.dll: Unable to load the test container 'C:\PublicShare\64Bit - Copy\Test64Bit\bin\x64\Debug\Test64Bit.dll' or one of its dependencies. If you build your test project assembly as a 64 bit assembly, it cannot be loaded. When you build your test project assembly, select "Any CPU" for the platform. To run your tests in 64 bit mode on a 64 bit processor, you must change your test settings in the Hosts tab to run your tests in a 32 bit process. Error details: Could not load file or assembly 'file:///C:\PublicShare\64Bit - Copy\Test64Bit\bin\x64\Debug\Test64Bit.dll' or one of its dependencies. An attempt was made to load a program with an incorrect format." when you try to run a unit test against an assembly that targets the x64 framework, which SharePoint Object Model must do.

It seems to me that the statement made by Microsoft is misleading, incomplete or misleading. Can someone please clarify?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不再见 2024-10-22 00:37:25

你用 SP1 beta 试过这个吗? SP1 今天发布了,我听说这确实有效。

Did you try this with SP1 beta? SP1 was released today and I hear that this does work.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文