簡體   English   中英

運行 XUnit 測試時 CefSharp 的 FileNotFoundException

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM