简体   繁体   English

为什么我所有的 Visual Studio 测试结果都“未执行”

[英]Why are all my Visual Studio test results "Not executed"

When I run my unit tests in my project I am seeing a result "Not executed" for every one.当我在我的项目中运行我的单元测试时,我看到每个测试结果“未执行”。 I have restarted my computer so I doubt this is some kind of hung process issue.我已经重新启动了我的计算机,所以我怀疑这是某种挂起的进程问题。

Google has revealed nothing.谷歌没有透露任何信息。 Does anyone have any ideas?有没有人有任何想法?

What a PITA!什么皮塔饼! The IDE doesn't show any errors. IDE 没有显示任何错误。 In order to determine the error you have to do this为了确定错误,您必须这样做

  1. Open the Visual Studio command prompt打开 Visual Studio 命令提示符
  2. Change to the directory where the binary output of your test project is.切换到测试项目的二进制输出所在的目录。
  3. Type mstest /testcontainer:The.Name.Of.Your.Test.Assembly.dll输入 mstest /testcontainer:The.Name.Of.Your.Test.Assembly.dll

At the bottom of the output you will see the following text在输出的底部,您将看到以下文本

Run has the following issue(s):运行有以下问题:

In my case it was the following:就我而言,情况如下:

Failed to queue test run 'Peter Morris@PETERMORRIS-PC 2009-02-09 10:00:37': Test Run deployment issue: The location of the file or directory 'C:\\SomePath\\SomeProject.Tests\\bin\\Debug\\Rhino.Mocks.dll' is not trusted.无法排队测试运行“Peter Morris@PETERMORRIS-PC 2009-02-09 10:00:37”:测试运行部署问题:文件或目录的位置“C:\\SomePath\\SomeProject.Tests\\bin\\Debug\\” Rhino.Mocks.dll' 不受信任。

Now if VS had told me this in the IDE I could have fixed it in minutes!现在,如果 VS 在 IDE 中告诉我这个,我可以在几分钟内修复它! All you have to do is open Windows Explorer and find that DLL.您所要做的就是打开 Windows 资源管理器并找到该 DLL。 Right-click on it and go to Properties.右键单击它并转到“属性”。 Then click the "Unblock" button.然后单击“取消阻止”按钮。

What a complete waste of my time!真是浪费我的时间!

Unit tests not executed未执行单元测试

I've found that it is good advice to never have a constructor for a unit test class.我发现永远不要为单元测试类设置构造函数是一个很好的建议。 If anything in a constructor ever throws, the test will just be reported as "not executed".如果构造函数中的任何内容抛出,则测试将仅报告为“未执行”。 Put test initialization in a TestInitialize method instead.将测试初始化​​放在 TestInitialize 方法中。 Exceptions thrown there are reported by the IDE.在那里抛出的异常由 IDE 报告。

Blocked Binaries被阻止的二进制文件

Usually you have to unblock the ZIP file itself before you extract binaries from it, and then all the binaries will be unblocked.通常,在从中提取二进制文件之前,您必须先解锁 ZIP 文件本身,然后才能解锁所有二进制文件。 If you try to unblock the binaries themselves the unblocking doesn't "stick".如果您尝试解锁二进制文件本身,解锁不会“坚持”。

Another reason for "Failed to queue test run 'XXX'. The path is not of a legal form. " is that the account does not have a profile loaded. “无法将测试运行 'XXX' 排队。路径不合法。 ”的另一个原因是该帐户没有加载配置文件。

Eg when you start mstest.exe with CreateProcessAsUser() and forget to call LoadUserProfile() as well.例如,当您使用 CreateProcessAsUser() 启动 mstest.exe 而忘记调用 LoadUserProfile() 时。

If you try to start a test run from IIS the "Failed to queue test run 'XXX'. The path is not of a legal form."如果您尝试从IIS启动测试运行,则会出现“无法将测试运行 'XXX' 排队。路径不合法。” can be thrown if the user who runs the application pool does not have a user profile .如果运行应用程序池的用户没有用户配置文件,则可以抛出。 In order to solve this just set Load User Profile to true in the application pool advanced settings.为了解决这个问题,只需在应用程序池高级设置中将 Load User Profile 设置为 true。

see https://social.msdn.microsoft.com/Forums/vstudio/en-US/7bb32a2d-7d10-4b8e-b743-e5beb1175917/trigger-mstest-from-app-hosted-on-iis?forum=csharpgeneral请参阅https://social.msdn.microsoft.com/Forums/vstudio/en-US/7bb32a2d-7d10-4b8e-b743-e5beb1175917/trigger-mstest-from-app-hosted-on-iis?forum=csharpgeneral

and https://blogs.msdn.microsoft.com/vijaysk/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool-identity/https://blogs.msdn.microsoft.com/vijaysk/2009/03/08/iis-7-tip-3-you-can-now-load-the-user-profile-of-the-application-pool -身份/

for more info欲了解更多信息

确保您的测试类和测试方法是公开的。

In my case I had a circular reference in my code.就我而言,我的代码中有一个循环引用。 Compile worked, but the tests just marked as "Not run".编译工作,但测试只是标记为“未运行”。

Sometimes the error could also be " Failed to queue test run 'XXX'. The path is not of a legal form. "有时错误也可能是“无法排队测试运行'XXX'。路径不合法。

The solution could be to change the TRX naming pattern in .testsettings file.解决方案可能是更改 .testsettings 文件中的 TRX 命名模式。

The quote from http://social.msdn.microsoft.com/Forums/da-DK/vststest/thread/c6efa2ba-1657-41bc-85b1-5a889d111e2f :引自http://social.msdn.microsoft.com/Forums/da-DK/vststest/thread/c6efa2ba-1657-41bc-85b1-5a889d111e2f

If you want control the name of this .trx file, open you Solution Explorer, open Local.testsettings in Solution Items, select General, change Default naming scheme to User-defined scheme.如果要控制此 .trx 文件的名称,请打开解决方案资源管理器,在解决方案项中打开 Local.testsettings,选择常规,将默认命名方案更改为用户定义的方案。 And then,进而,

  1. You could run the test with VS to get the .trx file you defined.您可以使用 VS 运行测试以获取您定义的 .trx 文件。

  2. If you want get this result in command line, you could run it with /testsettings:Local.Testsettings.如果你想在命令行中得到这个结果,你可以用 /testsettings:Local.Testsettings 运行它。 For more information, see http://msdn.microsoft.com/en-us/library/ms182489.aspx#testsettings .有关详细信息,请参阅http://msdn.microsoft.com/en-us/library/ms182489.aspx#testsettings

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

相关问题 在 C# Visual Studio 中执行所有测试脚本时执行代码 - Execute Code when all Test Scripts are executed in C# Visual Studio 为什么Visual Studio会在我的所有控件中添加“ p:”? - Why does visual studio add “p:” to all my controls? 在Visual Studio 2012测试资源管理器中保存结果 - Save Results in Visual Studio 2012 Test Explorer 根据它们在Visual Studio中执行的时间来排序测试 - Ordering test according to when they were executed in Visual Studio 为什么在我构建项目时Visual Studio没有在Test Explorer中给我测试? - Why Does Visual Studio not give me a test in Test explorer when I build my project? 为什么我的全部捕获都没有执行? - Why is my catch all not being executed? 如何在Visual Studio测试控制器中自动删除测试结果 - How to automatically delete Test Results in visual studio test controller 迭代器块的奇怪测试覆盖率结果,为什么这些语句没有被执行? - Weird test coverage results for iterator block, why are these statements not executed? 为什么我的Visual Studio单元测试中的每个测试都会触发TestInitialize? - Why does TestInitialize get fired for every test in my Visual Studio unit tests? 为什么我无法在我的 Visual Studio ASP.NET MVC 解决方案中创建单元测试? - Why am I not able to create unit test in my Visual Studio ASP.NET MVC solution?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM