我想对面向完整 .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/