4
votes

Visual Studio 2017, .Net CoreApp 1.1 (the target framework)

I need to write NUnit tests for my ASP.NET Core MVC web-application. I often used NUnit for my desktop-projects which were build on the base of .NET Framework 3.5-4.6.1.

I haven't the problem with xunit but I would like to use nunit.

Here I saw that at the current case I am to include such NuGet-packages:

  • dotnet-test-nunit
  • NUnit

But Test Explorer doesn't see my tests:

[TestFixture]
public class ProductTests {

    [Test]
    public void Name_Gets_ValidValue() {

        var name = "Bob";
        decimal price = 45.5M;

        Product p = new Product() { Name = name, Price = price };

        Assert.AreEqual(name, p.Name);
    }

    [Test]
    public void Name_Gets_ValidPrice() {

        var name = "Bob";
        decimal price = 45.5M;

        Product p = new Product() { Name = name, Price = price };

        Assert.AreEqual(price, p.Price);
    }
}

Hm... Ok. I tried to add NUnit3TestAdapter NuGet-package (I use it alwais), but this problem doesn't disappear.

How can I fix it?

1

1 Answers

4
votes

When .NET Core switched from the project.json format to the csproj format, it dropped support for the original .NET Core test adapter API, so the dotnet-test-nunit adapter no longer works with Visual Studio 2017 or the new .NET Core command line tools.

The new csproj format uses the old Visual Studio test adapter API, so the NUnit team needed to update that test adapter to support .NET Core. That work is nearly done in two PR's, one for the Visual Studio adapter and one for the NUnit Engine.

Once those two pull requests are merged, I will be creating an alpha release of the updated adapter, hopefully next week. Once I do so, I will update my blog with the new way to setup unit tests for .NET Core. In the meantime, you could make your unit tests self-executing using NUnitLite.

Sorry for the inconvenience, it took us longer than expected for the port to .NET Core.

Update: I have released an update to the NUnit Visual Studio Adapter that supports .NET Core. For information on how to use it, see Testing .NET Core with NUnit in Visual Studio 2017