microsoft / vstest

Visual Studio Test Platform is the runner and engine that powers test explorer and vstest.console.
MIT License
870 stars 316 forks source link

Test library referencing CefSharp cannot be run #4160

Closed jozefizso closed 3 days ago

jozefizso commented 3 years ago

Steps to reproduce

  1. Create class library project and add NUnit framework with adapter to it
  2. Add reference to CefSharp.OffScreen package
  3. Configure solution to use 64-bit platform
  4. Write test that will initialize the CefSharp framework and creates ChromiumWebBrowser object
  5. Create run settings file with disabled AppDomain
  6. Run vstest.console.exe ChromiumTests64.dll /Settings:DisableAppDomain.runsettings

See sample project at https://github.com/jozefizso/ChromiumUnitTests

Expected behavior

Unit tests should run.

Actual behavior

Test run will fail:

The active test run was aborted. Reason: Test host process crashed : Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp, Version=83.4.20.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.
   at CefSharp.Internals.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , scoped_refptr<CefCommandLine>* commandLine)
Unhandled Exception: System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp, Version=83.4.20.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.
   at CefSharp.Internals.CefSharpApp.OnContextInitialized(CefSharpApp* )

Test Run Aborted.

Environment

AB#1677596

nohwnd commented 3 years ago

Hello, please collect diagnostic output for this. This looks more like issue with CefSharp than test platform itself. https://github.com/microsoft/vstest-docs/blob/main/docs/diagnose.md

Evangelink commented 1 year ago

Hi @jozefizso,

Are you still experiencing the issue? If so, could you please follow the steps mentioned above by @nohwnd?

Evangelink commented 1 year ago

I can reproduce the issue with NUnit and MSTest which would seem to indicate it's more of a problem on Test Platform side. I will keep this ticket here for now and will try to do more investigation.

nohwnd commented 1 year ago

I can see that in vstest we are trying to locate the dll next to the testhost (i am using dotnet test, so the testhost is in dotnet-sdk location).

image

In NUnit a child process (CefSharp.BrowserSubprocess.exe) is started and CefSharp dll is located based on that.

But if it worked just like this, I don't see how any tests with any adapter could work. Because adapters load assemblies from the current folder normally.

nohwnd commented 3 days ago

I've updated the project to latest and it fails with:

image

I don't think this was ever vstest fault, in both cases cefSharp was crashing, and to me it looks like it took the testhost process with it.