简体   繁体   中英

VS Test Explorer is not finding my Unit Tests (XUnit.Runner) ASP.NET 5

I am using ASP.NET 5 with XUnit and Visual Studio is not finding my Tests in the test explorer.

I have rebuilt my project several times to get them to refresh. My test explorer is empty.

Any ideas?

Here is my project.json file:

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

  "dependencies": {
    "AutoFixture": "3.38.1",
    "AutoFixture.AutoMoq": "3.38.1",
    "BusinessLibrary": "1.0.0-*",
    "xunit": "2.1.0",
    "xunit.runner.dnx": "2.1.0-rc1-build204"
  },

  "frameworks": {
    "dnx451": { }
  }
}

Here is an example of one my my tests:

[Fact]
public void Traditional()
{
    // Arrange
    var sut = new Calculator();

    // Act
    sut.Subtract(1);

    // Assert
    Assert.True(sut.Value < 0);
}

You need to install the package XUnit.Runner.Console in your test project in order for the test runner to discover your tests.

https://www.nuget.org/packages/xunit.runner.console

With the following 3 XUnit specific properties in project.json , I got Visual Studio's Test Explorer to discover my XUnit tests:

{
  "version": "1.0.0-*",
  "testRunner": "xunit",
  "dependencies": {
    ...
    "xunit": "2.1.0",
    "dotnet-test-xunit": "2.2.0-preview2-build1029",
    ...
  },
  ...
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM