Configuring Nunit with ASP.NET MVC Core 1.0

I wanted to configure NUnit for my ASP.NET Core 1.0 project. I tried the following: http://www.alteridem.net/2015/11/04/testing-net-core-using-nunit-3/ , but it is there for console applications.

If I try to connect a new project (class library) to my solution, and then try to reference my original project, this gives me a reference error.

Here is what worked for me:

  • I applied another test application web application project to my original project, as opposed to the console library project.
  • Then I downloaded the NuGet packages for: "dotnet-test-nunit", "NUnit", "NUnit.Console" and "NUnit.Runners".
  • Then I wrote a test that worked after adding this line to project.json: "testRunner": "nunit"

This is the project.json file from my test project:

`

 {
  "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.1",
      "type": "platform"
    },
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "JustForTest": "1.0.0-*",
    "NUnit": "3.4.1",
    "NUnit.Runners": "3.4.1",
    "NUnit.Console": "3.4.1",
    "dotnet-test-nunit": "3.4.0-beta-2"
  },

  "tools": {
    "Microsoft.AspNetCore.Server.IISIntegration.Tools": "1.0.0-preview2-final"
  },

  "frameworks": {
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8"
      ]
    }
  },

  "buildOptions": {
    "emitEntryPoint": true,
    "preserveCompilationContext": true
  },

  "runtimeOptions": {
    "configProperties": {
      "System.GC.Server": true
    }
  },

  "publishOptions": {
    "include": [
      "wwwroot",
      "web.config"
    ]
  },
  "testRunner": "nunit",
  "scripts": {
    "postpublish": [ "dotnet publish-iis --publish-folder %publish:OutputPath% --framework %publish:FullTargetFramework%" ]
  }
}`

I have the following questions:

  • This is not like an optimized process - how can I optimize it?
  • Why the test did not work with the console application, is there anything you can do to complete this work?

Any help would be greatly appreciated. I am new to TDD and, in this regard, C # programming - if you have any suggestions in this context, please share this as well.

Thank.

0
source share
1 answer

NUnit.Runners NUnit.Console NuGet. , , NUnitLite, .NET Core NUnit . dotnet-test-nunit - . Visual Studio, Test Explorer dotnet test.

unit test .NET Core Class, -. :

  • .NET Core Class
  • dotnet-test-nunit NUnit NuGet
  • -
  • Visual Studio

NUnit 3 .NET Core ASP.NET Core.

ASP.NET Core , , , Startup .

+1

Source: https://habr.com/ru/post/1675158/


All Articles