Smartkid
Smartkid

Reputation: 1842

How to run nunit tests with asp.net 5 projects, especially with ReSharper?

I am developing an asp.net 5 application targeting dnx451.

The asp.net 5 project relies some libraries with unit-tests written for nunit 2.x. So the reasonable choice for me is to use nunit for testing the asp.net 5 project.

When I running the unit test in ReSharper, the ReSharper says "Test not run" with additional message "System.IO.FileNotFoundException: Could not load file or assembly xxx ".

Both nunit 2.6.4 and 3.0.0-beta-2 results the same error.

Any one has successfully running nunit tests against an dnx project?

Upvotes: 5

Views: 3098

Answers (4)

Stephen Oberauer
Stephen Oberauer

Reputation: 5395

Hopefully, by saying "Especially with ReSharper", you mean that you want to know how to run NUnit tests, and if possible, with ReSharper. That being said, here's how to run NUnit tests against ASP.NET Core (Formerly known as ASP.NET 5) in Visual Studio without needing ReSharper:

  1. Add a new project and choose Console Application (.NET Core). Trying to use class libraries will currently report an error.
  2. Add the latest version of the dotnet-test-nunit NuGet package (Make sure that Include prerelease is checked, or you won't find it in the NuGet feed)
  3. Add the latest version of the NUnit NuGet package.
  4. Edit project.json and add this line: "testRunner": "nunit",

Now you can run your tests by choosing Test - Run - All Tests from the Visual Studio menu.

Your project.json file should look like this:

{
  "version": "1.0.0-*",
  "buildOptions": {
    "emitEntryPoint": true
  },

  "dependencies": {
    "dotnet-test-nunit": "3.4.0-beta-1",
    "ProjectUnderTest": "1.0.0-*",
    "Microsoft.NETCore.App": {
      "type": "platform",
      "version": "1.0.0"
    },
    "NUnit": "3.4.1"
  },
  "testRunner": "nunit",

  "frameworks": {
    "netcoreapp1.0": {
      "imports": "dnxcore50"
    }
  }
}

Upvotes: 0

PleasantD
PleasantD

Reputation: 772

Looks like NUnit has (partial) support as of v3.0.0-RC http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/

Upvotes: 0

Ryan Walls
Ryan Walls

Reputation: 7092

NUnit does not support the DNX core.

Follow this issue to see when nunit adds dnx support. https://github.com/nunit/nunit/issues/575

Upvotes: 0

citizenmatt
citizenmatt

Reputation: 18583

DNX tests aren't currently supported by ReSharper. It's a whole new execution model, and hasn't yet been implemented for ReSharper. I'd expect to see support as DNX and asp.net stabilise and near release. Also, I don't believe nunit itself supports running as a DNX test runner - the xunit team have a separate project to plug into DNX: https://github.com/xunit/dnx.xunit

Upvotes: 3

Related Questions