gpt4 book ai didi

unit-testing - 将 asp.net 5 测试放在单独的程序集中

转载 作者:行者123 更新时间:2023-12-03 19:55:14 24 4
gpt4 key购买 nike

我使用 Microsoft.AspNet.TestHost 来托管 xunit 集成测试。只要测试与 asp.net-5-solution 在同一个项目中,一切都可以正常工作。
但我想将测试放入一个单独的程序集中,以将它们与解决方案分开。但是当我尝试在单独的解决方案中运行测试时出现错误,TestServer 找不到 View 。

Bsoft.Buchhaltung.Tests.LoginTests.SomeTest [FAIL]
System.InvalidOperationException : The view 'About' was not found. The following locations were searched:
/Views/Home/About.cshtml
/Views/Shared/About.cshtml.

我猜 TestServer 正在寻找相对于本地目录的 View 。我怎样才能让它在正确的项目路径中查找?

最佳答案

我这里有一个示例 repo - https://github.com/mattridgway/ASPNET5-MVC6-Integration-Tests这显示了修复(感谢大卫福勒)。

TL;DR - 设置 TestServer 时,您需要设置应用程序基本路径以查看其他项目,以便它可以找到 View 。

关于unit-testing - 将 asp.net 5 测试放在单独的程序集中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34590142/

24 4 0