Testing Asp.Net Core on full .NET framework

余生长醉 提交于 2019-12-23 17:31:33

问题


I want to unit test an asp.net core project that targets the full .net framework. I tried using the "normal" unit test project template and a .net core project as outlined in this blog post, but both attempts fail because the assembly of my web-project cannot be referenced in either of the test projects.

Is there a way to unit test asp.net core apps on the full framework?


回答1:


Found the solution in the comments section of the same blog post. As I cannot link directly, it is quoted below:

BillyboyD

In case anyone needs to do something similar, I have managed to set this up so I can test my controllers in an ASP.NET Core project that targets the .NET Framework 4.6.1 and also references class libraries that are standard .NET, not .NET core (we will have this hybrid situation for some time!). I am using VS2015 update 3 and .NET Core 1.0. My project.json is:

{
    "version": "1.0.0-*",
    "testRunner": "mstest",
    "dependencies": {
        "dotnet-test-mstest": "1.0.1-preview",
        "MSTest.TestFramework": "1.0.0-preview",
        "MyASP.NetCoreProject": "1.0.0-*"
    },
    "frameworks": {
        "net461": {
            "dependencies": {
                "MyClassLibrary": {
                    "target": "project"
                }
            }
        }
    }
}


来源:https://stackoverflow.com/questions/39167176/testing-asp-net-core-on-full-net-framework

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!