How can I run xUnit Unit Tests with VS2015 Preview?

纵饮孤独 提交于 2020-01-13 07:41:52

问题


I added the "xUnit.net runner for Visual Studio" v0.99.8 via Extensions Manager, but when I open the Test Explorer window, it does not seem to pick up any of my unit tests. Also, the Resharper 9 EAP does which is the only version of Resharper that supports VS2015 does seem yet to have the plugin for xUnit Test Runner.

How then, can I run xUnit Unit Tests in VS2015 Preview?


回答1:


You can find the answer here: http://blogs.msdn.com/b/webdev/archive/2014/11/12/announcing-asp-net-features-in-visual-studio-2015-preview-and-vs2013-update-4.aspx

Visual Studio supports running and debugging for ASP.NET 5 xUnit tests through test explorer. All you need to do is add the xUnit dependencies and test commands to the test project's project.json file, as shown below (NOTE: To install the xUnit packages you will need to add https://www.myget.org/F/aspnetvnext/api/v2 as a NuGet package source):

"dependencies": {
    "Xunit.KRunner": "1.0.0-beta1"
},

"commands": {
    "test": "Xunit.KRunner"
},

If anyone is asking how to add https://www.myget.org/F/aspnetvnext/api/v2 as a NuGet package source... here are the steps:

  1. In Visual Studio 2015 Preview go to Tools -> Options -> NuGet Package Manager -> Package Sources
  2. Click the Plus (Add) button at the top (see image below)
  3. Enter the Name and Source like in the image below (NOTE: be sure to click the Update button after entering the Name and Source)

Happy coding!




回答2:


You need to add reference to these 3 nuget packages:

"xunit": "2.1.0.0-beta1-build2945",
"xunit.runner.aspnet": "2.1.0.0-beta1-build60",
"xunit.runner.visualstudio": "2.1.0.0-beta1-build1051"

Check this article for more info: http://blog.developers.ba/unit-integration-testing-in-asp-net-5-and-visual-studio-2015-using-xunit-net/




回答3:


With visual studio 2015 RC I could not get tests to work with the following:

"xunit": "2.1.0-beta2-*",
"xunit.runner.dnx": "2.1.0-beta2-*"

But tests started showing up in the Test Explorer after changing the casing of the first letter "x" to "X"

"Xunit": "2.1.0-beta2-*",
"Xunit.runner.dnx": "2.1.0-beta2-*"

When I change it back to lower case it fails. I have not yet found a way to get these tests to show up in the latest version of Resharper at this time.

Here is the post I followed to get this far and everything worked except for the casing for some reason:

http://xunit.github.io/docs/getting-started-dnx.html

I know this will be out of date soon, but hopefully it helps someone in the mean time :)




回答4:


Regarding managing / running the tests through test explorer, it is available through nuget. I had to install package xunit.runner.visualstudio version 0.99.9-build1021 in the test projects. After building the solution, the tests showed up fine and I was able to run them.

BTW, this was for a windows service but should work for ASP.NET/Web projects.



来源:https://stackoverflow.com/questions/27018778/how-can-i-run-xunit-unit-tests-with-vs2015-preview

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