[英]Controller returns a null IActionResult when running xUnit test
[英]FileNotFoundException for CefSharp when running XUnit test
我正在使用 CefSarp 在应用程序上使用 XUnit 进行一些测试。
但测试崩溃,异常:
System.IO.FileNotFoundException:无法加载文件或程序集“CefSharp,版本 = 55.0.0.0,文化 = 中性,PublicKeyToken = 40c4b6fc221f4138”或其依赖项之一。 该系统找不到指定的文件。
在 CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp*, CefRefPtr* commandLine)
在 Xunit 问题跟踪器 ( https://github.com/xunit/xunit/issues/4 ) 上,解决方法是将 shadowCopy 选项设置为 false。 但这对我不起作用。
CefSharp 有一些文件需要成为可执行文件( https://github.com/cefsharp/CefSharp/wiki/Frequently-asked-questions#Runtime_dependencies )。 所有这些文件都存在于 bin 文件夹中,当我使用System.IO.Directory.GetCurrentDirectory()
检查当前目录时,这是正确的文件夹。
我尝试使用 Kernel32 中的SetDllDirectory
添加 bin 文件夹,但它没有任何改变。
我还尝试使用Assembly.LoadFile()
手动加载程序集。 此调用成功,但稍后在初始化 cef 时,仍会发生异常。 所以问题可能不是找到程序集本身,而是 CefSharp 需要的文件。
我应该把所有的 CefSharp 文件放在哪里才能让 XUnit 找到它们? 我对集成在 VisualStudio 中的 Xunit 测试和 Xunit 控制台有同样的问题。
编辑 :
问题已解决(请参阅 anwser)。 除了使用SpecFlow创建的测试外,所有测试都通过。
这次它抛出Could not load file or assembly
但使用 CefSharp.Core。
问题是 CefSharp 不支持多个 AppDomains。 CefSharp 存储库中单元测试的配置文件包含以下内容:
<configuration>
<appSettings>
<add key="xunit.appDomain" value="denied"/>
</appSettings>
</configuration>
这会阻止 XUnit 使用多个 AppDomain。 必须在每个测试库的app.config
中添加此配置。
CefSharp 测试还包含
var isDefault = AppDomain.CurrentDomain.IsDefaultAppDomain();
if (!isDefault)
{
throw new Exception(@"Add <add key=""xunit.appDomain"" value=""denied""/> to your app.config to disable appdomains");
}
检查是否使用了多个 AppDomain。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.