5

I have an F# Class Library with the "xUnit.net" and "xUnit.net Runners" packages installed using NuGet. I have the following code:

module XUnitTest

open Xunit

[<Fact>]
let Test () =
    do Assert.True (1 = 2)
    ()

When I run the xUnit GUI (xunit.gui.clr4.exe, which NuGet adds to (projectdirectory)\packages\xunit.runners.1.9.1\tools), and load the assembly built by this project, the Test () method appears, and fails when I run it, as expected.

However, I cannot get the test to appear in VS 2012's Test Explorer, no matter how many times I rebuild, restart, etc. If I click Run All, the build output window pops up but nothing else happens.

For the heck of it I also installed the xUnit.net Extensions, though I don't believe they're necessary for what I'm trying to do. That didn't help either.

Please let me know if I can provide additional information and thank you for reading!

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
FSharpN00b
  • 933
  • 1
  • 8
  • 17
  • Is the vs plugin [installed and] detecting your C# `[Fact]`s? – Ruben Bartelink May 20 '13 at 15:21
  • Good question. I made a C# Unit Test project and the built-in test did show up in Test Explorer. Then I used NuGet to get xUnit.net and xUnit.net Runners again, added a reference to Xunit, replaced the "TestMethod" attribute with "Fact", and rebuilt. No tests. I've used other NuGet packages, such as the FSharpx XAML type provider, successfully, and didn't get any obvious error messages about installing the Xunit.net packages. – FSharpN00b May 20 '13 at 19:56
  • related: http://stackoverflow.com/questions/16214684/why-is-the-xunit-runner-not-finding-my-tests – Ruben Bartelink May 21 '13 at 20:30
  • I just had this problem, but it was because I forgot to put the () at the end of the test method declaration... – Benjol Feb 13 '14 at 12:38

2 Answers2

6

Pretty sure based on the to/fro that you need to install xUnit.net runner for Visual Studio 2012 VSIX extension the xUnit.net runners NuGet package as detailed on the relevant xUnit docs page.

The MSTest equivalent is built in to a standard VS install.

Ruben Bartelink
  • 59,778
  • 26
  • 187
  • 249
  • Hi Ruben, I did install the xUnit.net Runners package through NuGet. That added the xUnit.net console and GUI executables to my (projectdirectory)\packages\xunit.runners.1.9.1\tools directory, which was how I was able to determine that xUnit.net by itself is able to see the tests in my assembly. It's just that some integration between xUnit and Visual Studio doesn't seem to be happening. – FSharpN00b May 21 '13 at 05:44
  • @FSharpN00b Exactly. There is a missing bit. It is the bit I've linked to. That bit is a plugin that sits into VS and scans Test Assemblies for *xUnit.net* Facts. You don't have it installed so it's not finding your C# or F# tests. So you need to follow the link and install that. I don't know a longer way of saying it ! – Ruben Bartelink May 21 '13 at 08:28
  • Hi Ruben, you were exactly right. I couldn't find a way for Visual Studio to browse to the vsix file that's available at the link you posted, but I was able to install it by going to the Tools menu, Extensions and Updates, and searching for xUnit.net runner. Now my test appears. I thought that the "xUnit.net runner for VS 2012" in Extensions and Updates was the same as the "xUnit.net: Runners" package available through NuGet. Obviously, I thought wrong, because it seems they are not the same. Thank you for clarifying this and I apologize for not getting it the first time. – FSharpN00b May 21 '13 at 09:42
  • So I guess the NuGet package is intended for people who want to have the console and GUI versions of xUnit available to run manually. I just uninstalled that package from my project and the tests still appear in Test Explorer and run as they should. – FSharpN00b May 21 '13 at 09:47
  • @FSharpN00b Yes, that figures - the VSIX package includes the [GUI] Runners. For other runners (CodeRush for one), the tools package needs to be somewhere (or you can download a Runners zip). I think for TD.NET one also needs the tools package. Obv by far the most common reason for having the runners package is, as you say, to run them in automated builds. – Ruben Bartelink May 21 '13 at 12:27
  • Now, it's deprecated and you should follow: http://xunit.github.io/docs/running-tests-in-vs.html – Philippe Jan 08 '15 at 16:12
  • @Philippe Thanks very much for the intaking the time to point that out -- edited in. – Ruben Bartelink Jan 08 '15 at 21:50
1

Be sure to search Including Prereleases. The package you need is 'xUnit.net [Visual Studio Runner]', which is a prerelease. If you only search for Stable releases, you will only find 'xUnit.net: Runners', which will not work in Visual Studio.

George H.
  • 21
  • 3