c# - 在完整的 .NET 框架上测试 Asp.Net Core

标签 c# .net unit-testing asp.net-core-1.0

我想对面向完整 .net 框架的 asp.net 核心项目进行单元测试。我尝试使用“正常”单元测试项目模板和 .net 核心项目,如 this blog post 中所述。 , 但两次尝试都失败了,因为在任何一个测试项目中都无法引用我的 web 项目的程序集。

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

最佳答案

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

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

关于c# - 在完整的 .NET 框架上测试 Asp.Net Core,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39167176/

相关文章:

c# - 无法理解拳击是如何完成的

c# - 从 IronPython 内部调用基于 CodeDom 的代码生成时出现 LoaderException

c# - 使用 Linq to SQL 进行单元测试实践

c# - 切换选项卡时关注控件

.net - 带有 PHP 客户端的 WCF 服务 - 复杂类型作为参数不起作用

unit-testing - 使用 NUnit 在 Hudson 中找不到测试报告文件

c# - 如何在 .Take() 之前获得总结果计数 - 但在使用 .Take() 时

c# - 在 MVVM Cross ViewModel 之间传递简单参数

unit-testing - Go - 表驱动测试辅助函数

python - 使测试使用我的服务器的多处理功能