在完整的 .NET 框架上测试 Asp.Net Core [英] Testing Asp.Net Core on full .NET framework

查看:26
本文介绍了在完整的 .NET 框架上测试 Asp.Net Core的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想对一个针对完整 .net 框架的 asp.net 核心项目进行单元测试.我尝试使用 这篇博文,但两次尝试都失败了,因为我的网络项目的程序集无法在任一测试项目.

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.

有没有办法在完整框架上对 asp.net 核心应用进行单元测试?

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

推荐答案

在同一篇博文的评论部分找到了解决方案.由于我不能直接链接,所以引用如下:

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

比利男孩

如果有人需要做类似的事情,我已经设法进行了设置,以便我可以在面向 .NET Framework 4.6.1 的 ASP.NET Core 项目中测试我的控制器,并且还引用了标准 .NET,而不是 .NET 核心(我们将在一段时间内遇到这种混合情况!).我正在使用 VS2015 更新 3 和 .NET Core 1.0.我的 project.json 是:

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

这篇关于在完整的 .NET 框架上测试 Asp.Net Core的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆