Vs2019 无法 运行 NUnit 测试 - 'testhost.x86.exe' 问题

Vs2019 cannot run NUnit Tests - Issue with 'testhost.x86.exe'

我使用 NUnit 创建了一个 selenium 测试框架,有一个测试可以打开页面并断言页面标题。

但是,当我尝试 运行 测试时,它似乎开始和停止时甚至没有做任何事情 运行 调试。测试保持 not run 状态。

当我在 { 和 运行 调试测试上设置断点时,没有任何变化。它在没有 运行 测试的情况下启动并立即停止。

测试:

[Test]
[TestCase(Browser.Chrome)]
public void ValidateWebDriverLaunches(Browser browser)
{
    Driver = StaticWebDriverFactory.GetLocalWebDriver(browser);
    Driver.Url = "https://example.com/";

    string title = Driver.Title;
    Assert.AreEqual(true, title.Contains("Example Domain"), "Title is not matching");
}

错误日志

'testhost.x86.exe' (CLR v4.0.30319: Domain 2): Unloaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'testhost.x86.exe' (CLR v4.0.30319: Dependency finder domain): Unloaded 'C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\Extensions\TestPlatform\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll'
The thread 0xcc has exited with code 0 (0x0).
'testhost.x86.exe' (CLR v4.0.30319: Domain 3): Unloaded 'C:\WINDOWS\Microsoft.Net\assembly\GAC_32\mscorlib\v4.0_4.0.0.0__b77a5c561934e089\mscorlib.dll'
'testhost.x86.exe' (CLR v4.0.30319: Dependency finder domain): Unloaded 'C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE\Extensions\TestPlatform\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll'
The thread 0x2f90 has exited with code 0 (0x0).
The thread 0x2f80 has exited with code 0 (0x0).
The program '[8948] testhost.x86.exe' has exited with code 0 (0x0).

我设置了环境变量

__UNITTESTEXPLORER_VSINSTALLPATH__

指向

C:\Program Files (x86)\Microsoft Visual Studio19\Professional\Common7\IDE

正如某些人所建议的那样。我发现的唯一其他建议是更新 VS17,但是我使用的是 VS19,找不到有关此版本的任何信息。

我发现问题出在我自己身上。

我安装了 NUnit3TestAdapter nuget 包,它现在可以正常工作了。

需要将Visual Studio中的进程架构切换到64。

Visual Studio:测试选项卡 -> AnyCPU 项目的进程架构 -> 64

我的问题真的很奇怪,我在 AppConfig 中的连接字符串在 上面,将它移到下面解决了我的问题。

在寻求解决方案的过程中,我找到了这个提示来帮助了解过早退出的原因:

转到 Test/Options 并将日志记录级别设置为“跟踪(包括平台日志)”。

在跟踪中,它说“NUnit 无法从 nuget 包引用加载 c:\...\netcoreapp3.1。NUnit 测试适配器 3.16.1 的下一步记录了测试执行完成,甚至虽然没有测试 运行。难道我们的 Nuget 包不包含 netcore?会 post 回来

我遇到了完全相同的问题,我尝试了 运行 UT 但它没有启动,在输出 window 中我看到的只是上述错误。 我解决问题的方式:

然后检查您的项目是否在构建字段中被选中,如果没有-标记它。