20

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?

Omer Raviv
  • 11,409
  • 5
  • 43
  • 82
  • See the issue here https://github.com/xunit/visualstudio.xunit/issues/31 – robi-y Nov 20 '14 at 17:34
  • Installed release of VS 2015 Community with all check box checked. I run XUnit tests without additional installations. But I got crash on running all test at once(all tests are single threaded and only managed code of github.com/EamonNerbonne/ExpressionToCode). So run them in small batches. – Dzmitry Lahoda Jul 23 '15 at 08:17

4 Answers4

14

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) enter image description here

Happy coding!

jflaga
  • 4,610
  • 2
  • 24
  • 20
  • 1
    I'm having trouble getting the Test Explorer to discover the tests when the project contains more than a few tests, for example, with tests from the Mvc project on GitHub. I filed a bug for this on Connect: https://connect.microsoft.com/VisualStudio/feedback/details/1099770 – Anthony Sneed Jan 24 '15 at 13:30
  • After I added the NuGet package source, I wasn't able to find the `xunit.Krunner` package, all xunit that I can find were: `xunit.execution` and `xunit.runner.utility` – Jaider Mar 23 '15 at 14:29
  • @Jaider maybe there are updates... please look at this: https://github.com/aspnet/Testing/wiki/How-to-create-test-projects ` { "dependencies": { "MyProject": "1.0.0-*", "xunit.runner.kre": "1.0.0-*" }, "frameworks": { "aspnet50": { }, "aspnetcore50": { } }, "commands": { "test": "xunit.runner.kre" } }` – jflaga Mar 27 '15 at 13:47
  • According to xUnits [twitter](https://twitter.com/xunit/status/569879015676190720) which ref this blog post: http://xunit.github.io/docs/getting-started-aspnet.html, we should use xunit.runner.aspnet. – Lejdholt Apr 13 '15 at 20:05
7

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/

Radenko Zec
  • 7,659
  • 6
  • 35
  • 39
  • what's the purpose of `"xunit.runner.visualstudio": "2.1.0.0-beta1-build1051"` ? for me it works without it. – Bart Calixto Mar 28 '15 at 22:09
  • That is strange. I thought that xunit.runner.visualstudio is for running test from visual studio and xunit.runner.aspnet for supporting new aspnet and running tests from console. – Radenko Zec Mar 30 '15 at 05:54
  • No. xunit.runner.visualstudio is used for desktop, PCL, Windows, and Windows Phone DLLs. xunit.runner.dnx is *both* the console and Visual Studio runner in one package. – Brad Wilson Jun 11 '15 at 16:09
5

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 :)

Matt Sanders
  • 953
  • 1
  • 13
  • 23
  • That's definitely not the case. Everybody I know who uses it -- myself included -- has no problem with lower-case x. It appears that NuGet package names are not case sensitive, so my best guess as to why one works and the other doesn't is that you have a corrupted package cache. – Brad Wilson Jun 11 '15 at 16:09
  • Whoah - I actually just ran in to this! and though, the casing X x thing was crazy, but same thing happened for me! – Nicholas Mayne Aug 31 '15 at 21:39
  • I had the same issue - make sure the nuget package names start with capital X. Otherwise, change the package versions via project.json and dnu restore to make them capitalized. – nh43de Oct 15 '15 at 05:56
0

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.

csaket
  • 41
  • 3