How can I debug unit test in Visual Studio 2017 15.6.0

时间:2018-03-09 19:08:44

标签: c# unit-testing visual-studio-2017 .net-core

Brand new machine, new install of Visual Studio 2017 Enterprise 15.6.0. I cannot seem to debug tests. I get the following error:

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

I can however run the test, but I need to step DEBUG through my tests.

6 个答案:

答案 0 :(得分:2)

如果您使用的是VS2017,请更新您的项目以使用netcore 2.0,它将起作用。

在安装VS2017并尝试调试使用netcore 1.0创建的项目后,出现了相同的问题。

答案 1 :(得分:2)

如果您使用的是 VPN连接,请先断开VPN连接,然后关闭VS2017,然后重新打开

答案 2 :(得分:0)

就我而言,

重新开启VS2017 停止实时单元测试会有效!

不过,我正在使用.NET.Core2.1 webApi项目。

答案 3 :(得分:0)

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

答案 4 :(得分:0)

在Windows 10上进行新安装时,我经常遇到这个问题。通常是在单元测试类中添加/删除其他测试/方法之后。

这是与VS 15.9.5和ASP.Net Core 2.2一起使用的。

重新启动Visual Studio可以修复该问题,直到下次。

答案 5 :(得分:0)

对我来说,清除缓存中的问题已解决

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

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