在完整的.NET Framework上进行Asp.Net Core测试

3
我想对一个目标为完整 .net 框架的 asp.net core 项目进行单元测试。我尝试使用“普通”的单元测试项目模板和根据此博客文章中说明的 .net core 项目,但两种尝试都失败了,因为我的 web 项目的程序集不能在任何测试项目中被引用。
有没有一种方法可以在完整框架上进行 asp.net core 应用的单元测试?

这个被踩是因为...? - Thaoden
1个回答

5

在同一篇博客文章的评论部分找到了解决方案。由于我无法直接链接,因此以下是引用:

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"
                }
            }
        }
    }
}

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接