Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

visual studio 2015 doesn't see my xunit tests

trying to add xunit tests to my ASP.NET 5 project, i've added a class library and fill the project.json like this :

{
  "version": "1.0.0-*",
  "description": "",
  "authors": [ "" ],
  "tags": [ "" ],
  "projectUrl": "",
  "licenseUrl": "",

  "dependencies": {
    "xunit": "2.1.0-beta2-build2981",
    "xunit.runner.visualstudio": "2.1.0-beta2-build1055"
  },
  "commands": {
    "test": "xunit.runner.visualstudio"
  },
  "frameworks": {
    "dnx451": { },
    "dnxcore50": {
      "dependencies": {
        "System.Collections": "4.0.10-beta-22816",
        "System.Linq": "4.0.0-beta-22816",
        "System.Threading": "4.0.10-beta-22816",
        "Microsoft.CSharp": "4.0.0-beta-22816"
      }
    }
  }
}

But Visual Studio doesn't recognize any of my unit tests in test explorer :

public class Class1
{
    [Fact]
    public void PassingTest()
    {
        Assert.Equal(4, Add(2, 2));
    }

    [Fact]
    public void FailingTest()
    {
        Assert.Equal(5, Add(2, 2));
    }

    int Add(int x, int y)
    {
        return x + y;
    }
}

What am I missing ?

like image 897
Tim Avatar asked May 29 '15 11:05

Tim


People also ask

Is xUnit compatible with .NET framework?

It's an open source unit testing tool for . Net framework that's compatible with ReSharper, CodeRush, TestDriven.Net, and Xamarin. You can take advantage of xUnit.Net to assert an exception type easily.

How do I enable test in Visual Studio?

To enable Live Unit Testing, select Test > Live Unit Testing > Start from the top-level Visual Studio menu.


1 Answers

I have had the same problem today. This solution works for me:

"dependencies": {
    "xunit": "2.1.0-beta3-*",
    "xunit.runner.dnx": "2.1.0-beta3-*",
    "xunit.runner.visualstudio": "2.1.0",
    "xunit.runners": "2.0.0"
  },
"commands": {
    "test": "xunit.runner.dnx"
  },

I hope this help you. I had to install 3 nuget package: xunit, xunit.runner.visualstudio and xunit.runners

like image 94
afonte Avatar answered Oct 12 '22 03:10

afonte