首页 新闻 会员 周边

ASP.NET Core 6 集成测试问题

0
悬赏园豆:30 [已解决问题] 解决于 2021-12-15 16:47

ASP.NET Core 集成测试(integration tests)需要用到 WebApplicationFactory<Program>,但 ASP.NET Core 6 的新型 Program.cs 中没有 Program 类名,如何指定 Program 给 WebApplicationFactory ?

dudu的主页 dudu | 高人七级 | 园豆:30994
提问于:2021-12-15 16:14
< >
分享
最佳答案
0

在 github 上的 Integration Testing ASP.NET Core 6 Minimal APIs 仓库发现一个巧妙的解决方法(Program.cs#L71),在 Program.cs 的结尾添加下面的代码:

public partial class Program
{
    // Expose the Program class for use with WebApplicationFactory<T>
}
dudu | 高人七级 |园豆:30994 | 2021-12-15 16:47
其他回答(1)
0
收获园豆:30
huiyuanai709 | 园豆:487 (菜鸟二级) | 2021-12-15 16:27
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册