简体   繁体   English

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

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

I am created a selenium test framework using NUnit have have a test to open a pages and assert the page title.我使用 NUnit 创建了一个 selenium 测试框架,有一个测试可以打开页面并断言页面标题。

However, when I try to run the test, its seems to start and stop without doing anything even running with Debug.但是,当我尝试运行测试时,它似乎启动和停止,甚至在运行调试时也没有做任何事情。 The test remains in the not run state.测试仍然在not run state 中。

When I put a break point on { and run the test with debug, nothing changes.当我在{上设置一个断点并使用调试运行测试时,没有任何变化。 It starts and instantly stops without running the test.它在不运行测试的情况下启动并立即停止。

Test:测试:

[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");
}

Error Log错误日志

'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 Studio\2019\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 Studio\2019\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).

I have set the environment variable我设置了环境变量

__UNITTESTEXPLORER_VSINSTALLPATH__

to point to指向

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

as some people have suggested.正如一些人所建议的那样。 The only other suggestions I have found is updating VS17, however I am using VS19 and cannot find any information on this version.我发现的唯一其他建议是更新 VS17,但是我使用的是 VS19,找不到有关此版本的任何信息。

I figure out that the issue was myself.我发现问题出在我自己身上。

I installed NUnit3TestAdapter nuget package and it works as expected now.我安装了NUnit3TestAdapter nuget package,它现在按预期工作。

It is required to switch process architecture in Visual Studio to 64.需要将 Visual Studio 中的进程架构切换到 64。

Visual Studio: Test Tab -> Process Architecture for AnyCPU Projects -> 64 Visual Studio:测试选项卡 -> AnyCPU 项目的进程架构 -> 64

My issue was really weird, my connection string in AppConfig was above the, moving it below solved my issue.我的问题真的很奇怪,我在 AppConfig 中的连接字符串在上面,将它移到下面解决了我的问题。

On the way to getting a solution, I found this tip to help see what the premature exit happens:在寻求解决方案的过程中,我发现了这个提示来帮助了解过早退出发生了什么:

Go to Test/Options and set the Logging level to "Trace (includes platform logs). Go 到测试/选项并将日志记录级别设置为“跟踪(包括平台日志)。

In the trace, it said "NUnit failed to load c:\...\netcoreapp3.1 from a nuget package reference. The very next step from the NUnit Test Adapter 3.16.1 logged Test Execution Complete, even though no tests were run. Could it be our Nuget pacakage doesn't include netcore? Will post back In the trace, it said "NUnit failed to load c:\...\netcoreapp3.1 from a nuget package reference. The very next step from the NUnit Test Adapter 3.16.1 logged Test Execution Complete, even though no tests were run . 会不会是我们的 Nuget 包不包括网核?会回帖

I had the exact same problem, I tried running UT and it did not start, and in the Output window all I saw was the above error.我遇到了完全相同的问题,我尝试运行 UT,但它没有启动,在 Output window 中,我看到的只是上述错误。 The way I solved the problem:我解决问题的方法: 在此处输入图像描述

And then check if your project is checked in build field, if not- mark it.然后检查您的项目是否已在构建字段中检查,如果没有,请标记它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM