How do you unit test an ASP.NET Core controller or model object?

前端 未结 3 1173
既然无缘
既然无缘 2020-12-15 05:47

I am trying to get some controller, model, and repository (data access) C# classes under unit test, in Visual Studio 2015, with ASP.NET Core MVC (ASP.NET 5 during the previe

3条回答
  •  暖寄归人
    2020-12-15 06:04

    With the release of RC2, the xUnit integration did not work any more with my projects (this has been fixed now see comments). To be able to test my projects I switched to NUnit. It appears to support RC2 and has a lightweight testrunner NUnitLite.

    Basically you need to host the NUnitLite into a console application and start it with "dotnet run".

    Add the following dependencies:

    "dependencies": {
        "NUnit": "3.2.1",
        "NUnitLite": "3.2.1",
    

    To start the test runner you need to add this code into the program.cs file:

    public class Program
    {
        public static void Main(string[] args)
        {
            new AutoRun().Execute(args);
        }
    }
    

提交回复
热议问题