MSTest 代码覆盖率

发布于 2024-09-04 23:01:11 字数 498 浏览 2 评论 0原文

我有一个 Web 服务的测试项目,当我在调试模式下运行测试时,一切正常。但是,当我刚刚运行测试时,对于我尝试获取代码覆盖率的引用程序集,出现以下错误:

类初始化方法 WebServiceTest.wstest.MyClassInitialize 引发异常。 System.IO.FileLoadException:System.IO.FileLoadException:无法加载文件或程序集“TestAssembly,Version=1.0.0.0,Culture=neutral,PublicKeyToken=57f286581e1d278a”或其依赖项之一。强名称验证失败。 (HRESULT 异常:0x8013141A) ---> System.Security.SecurityException:强名称验证失败。 (HRESULT 异常:0x8013141A)。 我发现的所有内容都说要在 GAC 中注册 TestAssembly。这是我应该做的吗?为什么它在调试模式下工作? 谢谢

I have a test project for a web service and, when I run tests in debug mode, everything works ok. However, when I just run tests, I get following error, for a referenced assembly that I try to obtain code coverage:

Class Initialization method WebServiceTest.wstest.MyClassInitialize threw exception. System.IO.FileLoadException: System.IO.FileLoadException: Could not load file or assembly 'TestAssembly, Version=1.0.0.0, Culture=neutral, PublicKeyToken=57f286581e1d278a' or one of its dependencies. Strong name validation failed. (Exception from HRESULT: 0x8013141A) ---> System.Security.SecurityException: Strong name validation failed. (Exception from HRESULT: 0x8013141A).
Everything I found said to register TestAssembly in GAC. Is this what should I do? Why is it working in debug mode?
Thank you

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

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

发布评论

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

评论(3

小女人ら 2024-09-11 23:01:11

我遇到了同样的问题,下面的链接帮助了我...

http://weblogs.asp.net/soever/archive/2005/07/23/420338.aspx

VS.NET 2005:签名程序集的代码覆盖率
我目前正在使用 VS.NET 2005 开发一个应用程序,因为单元测试和代码覆盖率等所有 TDD 工具都可用,所以我开始使用它们。

当我在签名的应用程序上开始代码覆盖时,出现以下异常:

测试方法 X 抛出异常:System.IO.FileLoadException:无法加载文件或程序集“Y,Version=1.0.0.0,Culture=neutral,PublicKeyToken=Z”或其依赖项之一。 HRESULT:0x8013141A 强名称验证失败。 ---> System.Security.SecurityException:来自 HRESULT 的异常:0x8013141A 强名称验证在 X 处失败。

如果您考虑一下,就不那么奇怪了。程序集已签名,代码覆盖率需要代码检测,意味着修改程序集,导致程序集不正确,从而验证失败。

解决方案是在仪表安装后退出装配。

如果您在解决方案项中打开 localtestrun.testrunco​​nfig 文件(或类似的文件)(双击它),则可以在“代码覆盖率”部分中启用重新签名。这解决了问题。

I had the same problem, and the link below helped me...

http://weblogs.asp.net/soever/archive/2005/07/23/420338.aspx

VS.NET 2005: Code coverage for signed assemblies
I am currently working on an application using VS.NET 2005, and because all the TDD tools like unit testing and code coverage are available I started to use them.

When I started code coverage on my signed application I got the following exception:

Test method X threw exception: System.IO.FileLoadException: Could not load file or assembly 'Y, Version=1.0.0.0, Culture=neutral, PublicKeyToken=Z' or one of its dependencies. HRESULT: 0x8013141A Strong name validation failed. ---> System.Security.SecurityException: Exception from HRESULT: 0x8013141A Strong name validation failed at X.

Not so strange if you think about it. Assembly is signed, code coverage needs code instrumentation, means modifications of the assembly, resulting in incorrect assembly so the validation failed.

Solution is to resign the assembly after instrumentation.

If you open the localtestrun.testrunconfig file (or something similar) in your solution items (double-click it), you can enable resigning in the Code Coverage section. This solves the problem.

始于初秋 2024-09-11 23:01:11

也可以通过执行以下命令来简单地禁用特定计算机上的所有签名程序集检查:

sn.exe -Vr *

但是,请小心使用,因为这会打开安全漏洞。我们在内部虚拟机上使用它来测量覆盖范围。查看 sn.exe 的用法,因为它可以缩小该命令的范围。

It is also possible to simply disable all signed assembly checking on a particular machine by executing:

sn.exe -Vr *

Use with care, however, as this opens a security vulnerability. We use this on our internal virtual machine that measures coverage for us. Take a look at the usage for sn.exe as it is possible to narrow the scope of that command.

梦途 2024-09-11 23:01:11

我正在使用 VS.Net Ultimate 2012

,这个解决方案帮助了我:

右键单击“测试项目”->“属性->构建选项卡->将生成序列化程序集切换为关闭->完毕

I am working with VS.Net Ultimate 2012

and this solution helped me:

Right click on Test Project-> properties-> Build Tab-> switch Generate serialization assembly to off-> done

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