unit-testing - 使用 TestServer 测试 ASP.NET Core 完整的 .NET Framework 给出了在 vs 2017 中找不到的方法

标签 unit-testing asp.net-core visual-studio-2017

尝试在 Visual Studio 2017 中运行测试时,所有编译都没有问题, 但是,当我尝试创建服务器和客户端进行测试时:

this.Server = new TestServer(
                new WebHostBuilder()
                    .UseStartup<Startup>()
                    .UseContentRoot(di.FullName));

 this.Client = this.Server.CreateClient();

TestServer 提示错误的依赖项(它尝试加载版本 1.0.0),即使 TestHost 包是:

<PackageReference Include="Microsoft.AspNetCore.TestHost" Version="1.1.1" />

同时测试失败并出现异常:

Cannot find method: 'System.Net.Http.HttpClient Microsoft.AspNetCore.TestHost.TestServer.CreateClient()'..

最佳答案

与VS 2017中错误的测试模板有关 在顶部手动添加 <PropertyGroup>

<GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>

csproj文件修复问题

关于unit-testing - 使用 TestServer 测试 ASP.NET Core 完整的 .NET Framework 给出了在 vs 2017 中找不到的方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42697281/

相关文章:

node.js - 如何使用 Jest 测试 Electron ipc 事件?

unit-testing - 测试访问Item.constraints.xyz的类时,如何摆脱 “no such property”?

javascript - yeoman gulp-angular projekt 设置后单元测试出错

Asp.net 5 MVC 6, 为 facebook 电子邮件添加权限

c# - Entity Framework 核心3.0-捕获错误

c# - automapper 中没有为此对象定义无参数构造函数

c# - 当我查看它们时,数百个错误都消失了吗?

java - 多次运行特定的 JUnit 测试,但排除其他测试多次运行

Typescript 调试在 Visual Studio 2017 中不起作用

c++ - Visual Studio 2017 中的 UTF-8 支持 std::experimental::filesystem::path