如何在Visual Studio 2017 15.6.0中调试单元测试

4

全新的机器,安装了Visual Studio 2017 Enterprise 15.6.0。

我似乎无法调试测试。我得到了以下错误:

Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException: Failed to launch testhost with error: System.AggregateException: One or more errors occurred. () ---> Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException
   at Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient.LaunchCustomHost(TestProcessStartInfo testProcessStartInfo)
   at Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeTestHostLauncher.LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.<LaunchTestHostAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<LaunchTestHostAsync>d__37.MoveNext()
   --- End of inner exception stack trace ---
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task`1.GetResultCore(Boolean waitCompletionNotification)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
---> (Inner Exception #0) Microsoft.VisualStudio.TestPlatform.ObjectModel.TestPlatformException
   at Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeClient.LaunchCustomHost(TestProcessStartInfo testProcessStartInfo)
   at Microsoft.VisualStudio.TestPlatform.Client.DesignMode.DesignModeTestHostLauncher.LaunchTestHost(TestProcessStartInfo defaultTestHostStartInfo)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.LaunchHost(TestProcessStartInfo testHostStartInfo, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<>c__DisplayClass37_0.<LaunchTestHostAsync>b__0()
   at System.Threading.Tasks.Task`1.InnerInvoke()
   at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot)
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Hosting.DotnetTestHostManager.<LaunchTestHostAsync>d__37.MoveNext()<---

   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyOperationManager.SetupChannel(IEnumerable`1 sources, CancellationToken cancellationToken)
   at Microsoft.VisualStudio.TestPlatform.CrossPlatEngine.Client.ProxyExecutionManager.StartTestRun(TestRunCriteria testRunCriteria, ITestRunEventsHandler eventHandler)
 Summary: Passed: 0, Failed: 0, Ignored: 0
Duration: 4.82 seconds

我可以运行测试,但是我需要通过调试我的测试。


让你的求助呼声在粗体字中尖叫可能会产生不同于你想象的效果。否则,欢迎来到SO! - user2819245
5
请使用“帮助”>“发送反馈”>“报告问题”来汇报15.6.0版本的错误。 - Hans Passant
@elgonzo 谢谢您! - Charles
可能相关:https://developercommunity.visualstudio.com/content/problem/174688/issues-with-unit-test-framework.html - StriplingWarrior
上面提到了断开VPN连接。但对我来说恰恰相反,只有在连接时调试才有效。 - Piotr Bocian
6个回答

3
如果您使用了 VPN 连接,请先断开 VPN,然后关闭 VS2017 并重新打开。

2
如果您正在使用VS2017,请将项目更新为使用netcore 2.0,它将正常工作。
在安装VS2017并尝试调试使用netcore 1.0创建的项目后,我遇到了同样的问题。

2

在安装了Windows 10的新电脑上,我偶尔会遇到这个问题。通常是在我的单元测试类中添加/删除其他测试/方法之后。

这是使用VS 15.9.5和ASP.Net Core 2.2时发生的。

重新启动Visual Studio可以解决这个问题,直到下一次出现。

"Original Answer"翻译成中文是"最初的回答"。


0
在我的情况下,重新打开VS2017或停止Live Unit Testing都可以解决问题!顺便说一句,我正在使用.NET Core2.1 WebApi项目。

0

对我来说,问题通过清除缓存得到解决。

C:\Users\mdasari\AppData\Local\NuGet, C:\Users\mdasari.nuget

清理解决方案,然后运行测试用例。

0

以管理员身份运行VS,解决了我的问题。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接