xUnit.net v2 未在 Visual Studio 2015 中发现 .NET Core 测试 [英] xUnit.net v2 not discovering .NET Core Tests in Visual Studio 2015
问题描述
我对这个问题感到非常沮丧.我已经尝试更改版本号,但测试资源管理器中未显示任何测试.
I am really frustrated with this issue. I have already tried changing the version numbers but no tests are showing in the test explorer.
在测试输出窗口中我可以看到这个输出
In the test output window I can see this output
Starting Microsoft.Framework.TestHost [C:Userssul.dnx
untimesdnx-clr-win-x86.1.0.0-beta4indnx.exe --appbase "path to test project" Microsoft.Framework.ApplicationHost --port 63938 Microsoft.Framework.TestHost --port 63954 list ]
Unable to start Microsoft.Framework.TestHost
========== Discover test finished: 0 found (0:00:36.5471185) ==========
这太脆弱了,有时会显示测试,然后它们就永远消失了.重新启动 VS 没有帮助,重新安装 xunit/xunit runner 也没有帮助.
This is so fragile, sometimes tests are shown then they disappear for good. Restarting VS didn't help, reinstalling the xunit/xunit runner didn't help either.
在另一个测试项目中,我得到了不同的输出,但仍未显示测试
In another test project I got a different output but still not tests are showing
Starting Microsoft.Framework.TestHost [C:Userssul.dnx
untimesdnx-clr-win-x86.1.0.0-beta4indnx.exe --appbase "path to project" Microsoft.Framework.ApplicationHost --port 63938 Microsoft.Framework.TestHost --port 64421 list ]
Connected to Microsoft.Framework.TestHost
Discovering tests in 'path to projectproject.json'
========== Discover test finished: 0 found (0:00:35.9341416) ==========
这是我的 project.json 的一部分
This is part of my project.json
"commands": {
"test": "xunit.runner.dnx"
},
"dependencies": {
"Microsoft.AspNet.Http": "1.0.0-*",
"Microsoft.AspNet.Http.Core": "1.0.0-*",
"Microsoft.AspNet.TestHost": "1.0.0-*",
"Moq": "4.2.1502.911",
"xunit": "2.0.0",
"xunit.runners": "2.0.0"
推荐答案
我设法通过确保所有解决方案项目中的所有包都引用相同版本来使其工作.
I manage to get this to work by making sure that all the packages in all the solution projects reference the same version.
这发生在我身上,因为我引用了最新版本,正如您在 project.json 中看到的那样.
This happened to me because I was referencing the latest versions as you can see from project.json.
我做的另一件事是从不引用仅适合目的的单个包.例如,在我的业务项目中,我正在创建一个中间件并且我引用了 Microsoft.AspNet.Http,因为我不需要完整的 MVC 包.这导致测试项目出现问题,因此我将 Microsoft.AspNet.MVC 添加到任何需要任何类型的 Http 交互(即 httpcontext)的项目中.
One other thing I did is never reference individual packages which fits the purpose only. For example in my business project I am creating a middleware and I was referencing Microsoft.AspNet.Http because I don't need the full MVC package. This caused issues in the test project so I added Microsoft.AspNet.MVC to any project that needs any sort of Http interaction i.e. httpcontext.
这可能不是理想的解决方案,但它确实对我有用.我希望这能帮助遇到同样问题的其他人.
This may not be the ideal fix but it did work for me. I hope this helps someone else experiencing the same issue.
这篇关于xUnit.net v2 未在 Visual Studio 2015 中发现 .NET Core 测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!