【发布时间】:2021-03-02 07:44:04
【问题描述】:
我无法从 VS 内部运行测试。我只用模板中的一个 NUnit 测试项目和一个使用 Assert.IsTrue(true) 的测试创建了最简单的解决方案。
以下是我添加到项目中的 NuGet 包及其版本,以防万一:
- Microsoft.NET.Test.Sdk 16.8.0
- NUnit 3.12.0
- NUnit3TestAdapter 3.17.0
这是我使用 dotnet test [projName] 从命令行运行测试时得到的输出:
Determining projects to restore...
Restored /Users/OpenMinder/DevTraining/Test/Test.csproj (in 331 ms).
Test -> /Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.dll
Test run for /Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.dll (.NETCoreApp,Version=v3.1)
Microsoft (R) Test Execution Command Line Tool Version 16.8.0
Copyright (c) Microsoft Corporation. All rights reserved.
Starting test execution, please wait...
A total of 1 test files matched the specified pattern.
Passed! - Failed: 0, Passed: 1, Skipped: 0, Total: 1, Duration: 29 ms - /Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.dll (netcoreapp3.1)
但每当我尝试从 VS for mac 运行它们时,我都会得到以下行为:
-
测试名称不显示在面板中
-
测试运行未完成
-
我在输出中收到以下错误:
Failed to launch testhost with error: System.AggregateException: One or more errors occurred. (ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file) ---> System.ComponentModel.Win32Exception: ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file
at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0029f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/System/System.Diagnostics/Process.cs:778
at System.Diagnostics.Process.Start () [0x0003a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2006
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.LaunchProcess (System.String processPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.IDictionary`2[TKey,TValue] envVariables, System.Action`2[T1,T2] errorCallback, System.Action`1[T] exitCallBack) [0x00101] in <06d9ef76610d4473ae17230fef5fa07d>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x0006d] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager+<>c__DisplayClass34_0.<LaunchTestHostAsync>b__0 () [0x00000] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchTestHostAsync (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x00096] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2029
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:496
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:466
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel (System.Collections.Generic.IEnumerable`1[T] sources) [0x00115] in <c4016cc04b6c4d6fb0610501f99366ce>:0
---> (Inner Exception #0) System.ComponentModel.Win32Exception (0x80004005): ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file
at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0029f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/System/System.Diagnostics/Process.cs:778
at System.Diagnostics.Process.Start () [0x0003a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2006
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.LaunchProcess (System.String processPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.IDictionary`2[TKey,TValue] envVariables, System.Action`2[T1,T2] errorCallback, System.Action`1[T] exitCallBack) [0x00101] in <06d9ef76610d4473ae17230fef5fa07d>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x0006d] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager+<>c__DisplayClass34_0.<LaunchTestHostAsync>b__0 () [0x00000] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchTestHostAsync (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x00096] in <8b213d9f519447a3ad29e7a4013d8bc9>:0 <---
Failed to launch testhost with error: System.AggregateException: One or more errors occurred. (ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file) ---> System.ComponentModel.Win32Exception: ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file
at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0029f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/System/System.Diagnostics/Process.cs:778
at System.Diagnostics.Process.Start () [0x0003a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2006
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.LaunchProcess (System.String processPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.IDictionary`2[TKey,TValue] envVariables, System.Action`2[T1,T2] errorCallback, System.Action`1[T] exitCallBack) [0x00101] in <06d9ef76610d4473ae17230fef5fa07d>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x0006d] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager+<>c__DisplayClass34_0.<LaunchTestHostAsync>b__0 () [0x00000] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchTestHostAsync (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x00096] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
--- End of inner exception stack trace ---
at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00013] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2029
at System.Threading.Tasks.Task`1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:496
at System.Threading.Tasks.Task`1[TResult].get_Result () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:466
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel (System.Collections.Generic.IEnumerable`1[T] sources) [0x00115] in <c4016cc04b6c4d6fb0610501f99366ce>:0
---> (Inner Exception #0) System.ComponentModel.Win32Exception (0x80004005): ApplicationName='/usr/local/bin/dotnet', CommandLine='exec --runtimeconfig "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.runtimeconfig.json" --depsfile "/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1/Test.deps.json" "/Users/OpenMinder/.nuget/packages/microsoft.testplatform.testhost/16.8.0/lib/netcoreapp2.1/testhost.dll" --port 56039 --endpoint 127.0.0.1:056039 --role client --parentprocessid 8638 --telemetryoptedin false', CurrentDirectory='/Users/OpenMinder/DevTraining/Test/bin/Debug/netcoreapp3.1', Native error= Cannot find the specified file
at System.Diagnostics.Process.StartWithCreateProcess (System.Diagnostics.ProcessStartInfo startInfo) [0x0029f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/System/System.Diagnostics/Process.cs:778
at System.Diagnostics.Process.Start () [0x0003a] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/mcs/class/referencesource/System/services/monitoring/system/diagnosticts/Process.cs:2006
at (wrapper remoting-invoke-with-check) System.Diagnostics.Process.Start()
at Microsoft.VisualStudio.TestPlatform.PlatformAbstractions.ProcessHelper.LaunchProcess (System.String processPath, System.String arguments, System.String workingDirectory, System.Collections.Generic.IDictionary`2[TKey,TValue] envVariables, System.Action`2[T1,T2] errorCallback, System.Action`1[T] exitCallBack) [0x00101] in <06d9ef76610d4473ae17230fef5fa07d>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x0006d] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager+<>c__DisplayClass34_0.<LaunchTestHostAsync>b__0 () [0x00000] in <8b213d9f519447a3ad29e7a4013d8bc9>:0
at System.Threading.Tasks.Task`1[TResult].InnerInvoke () [0x0000f] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Future.cs:534
at System.Threading.Tasks.Task.Execute () [0x00000] in /Users/builder/jenkins/workspace/build-package-osx-mono/2020-02/external/bockbuild/builds/mono-x64/external/corert/src/System.Private.CoreLib/src/System/Threading/Tasks/Task.cs:2319
--- End of stack trace from previous location where exception was thrown ---
at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchTestHostAsync (Microsoft.VisualStudio.TestPlatform.ObjectModel.TestProcessStartInfo testHostStartInfo, System.Threading.CancellationToken cancellationToken) [0x00096] in <8b213d9f519447a3ad29e7a4013d8bc9>:0 <---
VS 8.8 版本 2913
macOS Catalina 10.15.7
我当前的 dotnet 信息:
.NET SDK (reflecting any global.json):
Version: 5.0.100
Commit: 5044b93829
Runtime Environment:
OS Name: Mac OS X
OS Version: 10.15
OS Platform: Darwin
RID: osx.10.15-x64
Base Path: /usr/local/share/dotnet/sdk/5.0.100/
Host (useful for support):
Version: 5.0.0
Commit: cf258a14b7
.NET SDKs installed:
3.1.404 [/usr/local/share/dotnet/sdk]
5.0.100 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
有人知道我还能尝试什么吗?
如果您需要更多信息,请告诉我。
【问题讨论】:
-
在终端,
dotnet test告诉你什么? -
嗨@LexLi 我已将 dotnet 测试的结果添加到描述中。对我来说这看起来很正常。我知道我总是可以以这种方式运行测试,但我需要一个 VS IDE 来用于我正在启动的项目,而且我很确定在某些时候我需要调试测试。
-
两者比较表明
dotnet test只检测/Users/OpenMinder/DevTraining/Test为测试项目,而VS for Mac检测/Users/OpenMinder/Dev training/eco-bonus/Api/Api.UnitTests为测试项目。您可能会进一步挖掘,看看可能出了什么问题。 -
@LexLi 好地方,但那是我的错误。输出来自我的真实项目,但 dotnet 测试结果来自更简单的版本。我现在更新了输出日志以匹配更简单的解决方案。看起来可疑的是,在输出日志中它正在寻找 microsoft.testplatform.testhost 包的 netcoreapp2.1 版本,并且该项目位于 .NET Core 3.1 中(我没有此包的 netcoreapp3.1 文件夹即使是最新的稳定版本 16.8.0)。
标签: c# macos visual-studio-code nunit