MSTest code coverage

大兔子大兔子 提交于 2019-12-23 19:10:31

问题


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


回答1:


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.




回答2:


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.




回答3:


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



来源:https://stackoverflow.com/questions/2989037/mstest-code-coverage

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!