xUnit.net v2在Visual Studio 2015中找不到.NET Core测试 [英] xUnit.net v2 not discovering .NET Core Tests in Visual Studio 2015

查看:153
本文介绍了xUnit.net v2在Visual Studio 2015中找不到.NET Core测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对此问题感到非常沮丧。我已经尝试过更改版本号,但是测试浏览器中未显示任何测试。

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:\Users\sul\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.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运行器也无济于事。

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:\Users\sul\.dnx\runtimes\dnx-clr-win-x86.1.0.0-beta4\bin\dnx.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 project\project.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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆