VS 2010 错误生成单元测试

发布于 2024-09-12 03:53:57 字数 606 浏览 1 评论 0原文

我有一个 .NET 4 DLL,无法为其生成单元测试。我使用的是 VS 2010 标准版。解决方案中的每个其他项目都会为类生成单元测试存根。对于其他程序集,我可以进入现有代码,右键单击类名称,然后选择“创建单元测试”。我得到了接下来的选择窗口。

我真正需要进行一些覆盖的一个程序集不会使用上述相同的方法生成测试存根。我转到项目/程序集中的一个类,右键单击,选择“生成单元测试”,然后遇到以下错误:

单元测试生成错误:读取模块“xx.Core”时遇到以下错误:无法解析类型引用:[System.Web,Version=2.0.0.0,Culture=neutral,PublicKeyToken=xxxxxxxxxxxx]System.Web .Routing.RouteValueDictionary

据我所知,项目中没有直接引用错误消息中提到的 System.Web 框架 2.0 版本。使用名为 grepWIN 的工具搜索包含项目和 .CS 文件的目录,查看任何文件中是否存在该引用的文本,结果为零。是否有可能同时引用 2.0 和 4.0 版本的 system.web dll?如果可以,为什么要这样做?

关于如何消除此错误消息以便我可以正确地删除一些单元测试的任何想法?

I have one .NET 4 DLL for which I'm having trouble generating unit tests. I'm using VS 2010 Standard. Every other project in the solution will generate unit test stubs for classes just fine. For the other assemblies, I can go into the existing code, right click the class name, and select "Create Unit Tests". I get the selection window that follows just fine.

The one assembly that I really need to get some coverage on won't generate the test stubs using the same methodology mentioned above. I go to a class in the project/assembly, right click, select "Generate Unit Tests", and I'm met with the following error:

Unit Test Generation Error: The follow error was encountered while reading module 'xx.Core': Could not resolve type reference: [System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=xxxxxxxxxxxx]System.Web.Routing.RouteValueDictionary

As far as I can tell, there are no direct references in the project to the framework 2.0 version of System.Web mentioned in the error message. Searching the directory that contains the project and .CS files with a tool called grepWIN to see if the text for that reference exists in any files yields zero results. Is it even possible to reference both the 2.0 and 4.0 version of the system.web dll at the same time, and if so, why would you want to do that?

Any ideas on how to get rid of this error message so that I can properly stub out some unit tests?

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

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

发布评论

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

评论(3

魄砕の薆 2024-09-19 03:53:57

我对 ObservableCollection 也有同样的问题。

我的“解决方案”是将所有引用的项目及其引用的项目升级到.NET 4.0。然后它就起作用了......但是这看起来有点奇怪,我很可能做了其他一些事情来导致问题消失。

I had the same problem, with the ObservableCollection.

My "solution" was to upgrade all referenced projects and their referenced projects to .NET 4.0. Then it worked.... However this seems a bit odd and I could well have done something else that caused the problem to disappear.

﹂绝世的画 2024-09-19 03:53:57

我最近在我的一个项目中遇到了类似的问题。问题是,在构建库后,我重命名了 dll 文件。我引用该 dll 的项目仍然可以正常构建,但是在生成单元测试时我收到了类似的错误,直到我在构建该 dll 时将其重命名回其原始名称。

I recently had a similar problem with one of my projects. The problem was that after I had built my library I renamed the dll file. My project referencing the dll still built fine, however I received a similar error while generating unit tests until I renamed the dll back to its original name when it had been built.

真心难拥有 2024-09-19 03:53:57

您使用 NUNIT 进行单元测试吗?如果是这样,默认情况下 Nunit 指向 .Net 2.0。您需要对 nunit.exe.config 文件进行适当的更改。

请在 Windows 资源管理器中导航至 C:\WINDOWS\Microsoft.NET\Framework。在那里您将看到许多具有此类名称的文件夹:v1.0.xxxxx、v1.1.xxxxx、...、v4.0.xxxxx。记下 v4.0.xxxxx 文件夹的确切名称。

使用文本编辑器打开文件 nunit.exe.config,该文件位于以下文件夹中:C:\Program Files\NUnit 2.5.2\bin\net-2.0。

在添加下:

<startup>  <requiredRuntime version="v4.0.xxxxx" />  </startup>

[用您写下的正确数字替换 xxxxx]

并在添加下:

<loadFromRemoteSources enabled="true" />

上述更改对我有用。希望对于其他面临这个问题的人来说。

Are you using NUNIT for unit test? If so, by default Nunit points to .Net 2.0. You need to make appropriate changes to the nunit.exe.config file.

Could you please, in Windows Explorer, navigate to C:\WINDOWS\Microsoft.NET\Framework. There you will see a number of folders with names of this kind: v1.0.xxxxx, v1.1.xxxxx, ..., v4.0.xxxxx. Write down the exact name of the v4.0.xxxxx folder.

With a text editor open up the file nunit.exe.config, which is in this folder: C:\Program Files\NUnit 2.5.2\bin\net-2.0.

Under add:

<startup>  <requiredRuntime version="v4.0.xxxxx" />  </startup>

[replace xxxxx by the correct numbers that you wrote down]

and under add:

<loadFromRemoteSources enabled="true" />

The above change worked for me. Hopefully for other people who are facing this problem.

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