简体   繁体   English

Visual Studio 2010 是否只运行 4.0 单元测试?

[英]Will Visual Studio 2010 only run 4.0 unit tests?

I have different projects written in .NET 3.5 and some unit test projects to cover them.我有用 .NET 3.5 编写的不同项目和一些单元测试项目来覆盖它们。 When converting my solution to be used in Visual Studio 2010 I keep all my projects in 3.5 but the unit tests are forced to 4.0?将我的解决方案转换为在 Visual Studio 2010 中使用时,我将所有项目保留在 3.5 中,但单元测试被强制为 4.0? This way I cannot use them with my regular projects anymore.这样我就不能再在我的常规项目中使用它们了。

Resulting in this: Could not load file or assembly 'xxx.xxx.Core.UnitTest' or one of its dependencies.结果是:无法加载文件或程序集“xxx.xxx.Core.UnitTest”或其依赖项之一。 This assembly is built by a runtime newer than the currently loaded runtime and cannot be loaded.此程序集由比当前加载的运行时更新的运行时构建,无法加载。

So I can't unit test any project less then 4.0?所以我不能对低于 4.0 的任何项目进行单元测试? Or am I doing something wrong here?或者我在这里做错了什么?

Currently the sad answer is yes - only tests created with VS2010 (.NET 4.0) are supported.目前令人遗憾的答案是肯定的 - 仅支持使用 VS2010 (.NET 4.0) 创建的测试。

Apparently this one done on purpose - take a look at this "bug" report at Microsoft connect for details.显然这是故意完成的 - 请查看Microsoft Connect上的这个“错误”报告以了解详细信息。

Update更新
after Microsoft's has seen the error of their way they have added .NET 3.5 unit tests support in VS2010 SP1 - the full details can be found in this post .在微软看到他们的方式错误后,他们在 VS2010 SP1 中添加了 .NET 3.5 单元测试支持——完整的细节可以在这篇文章中找到。

You can also re-target existing .NET 4.0 unit tests - How to re-target unit-tests to .Net Framework 3.5 in VS 2010 SP1您还可以重新定位现有的 .NET 4.0 单元测试 - 如何在 VS 2010 SP1 中将单元测试重新定位到 .Net Framework 3.5

While test projects get converted to Visual Studio 2010 Test Project and compiled targeted for the .NET 4.0 framework luckily all the assemblies that you reference and test in your tests can still be .NET 3.5 (or whatever) assemblies.虽然测试项目被转换为 Visual Studio 2010 测试项目并针对 .NET 4.0 框架进行编译,但幸运的是,您在测试中引用和测试的所有程序集仍然可以是 .NET 3.5(或其他)程序集。 Anything else would be disastrous.否则将是灾难性的。 But yes, you can no longer use Visual Studio 2008 to run those test projects.但是是的,您不能再使用 Visual Studio 2008 来运行这些测试项目。

A workaround, of course, would be to keep the source code for the tests, but have two different test projects, one for VS2008, and one for VS2010 using that same test source code.当然,一种解决方法是保留测试的源代码,但有两个不同的测试项目,一个用于 VS2008,另一个用于使用相同测试源代码的 VS2010。 Cumbersome, but a working solution.麻烦,但一个有效的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM